英文:
Is the any way to create String Literal Types in Java?
问题
我对Java还不熟悉。
我一直在前端使用TypeScript为项目进行类型设置,我非常习惯于创建字符串字面类型来限制可能的输入。在Java中有没有简单的方法可以实现这一点?
为了美观起见,以下是在TypeScript中创建它的方式:
type Easing = "ease-in" | "ease-out" | "ease-in-out";
英文:
I'm new to Java.
I've been using Typescript to type my projects in the Front-end and I'm very used to creating String Literal Types to limit possible inputs. Is there any easy way to this in Java?
For eye candy, here's how you create it in Typescript:<br>
type Easing = "ease-in" | "ease-out" | "ease-in-out";
答案1
得分: 1
最相似的东西是一个 enum
类型。
public enum Easing {
EASE_IN, EASE_OUT, EASE_IN_OUT;
}
英文:
No. The most similar thing is an enum
Type.
public enum Easing {
EASE_IN, EASE_OUT, EASE_IN_OUT;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论