开发者

How do I use an Enum in another Java class?

I have a Java file which is solely an enum:

public enum MyEnum {
    ONE, TWO, THREE;
}

And I want to开发者_StackOverflow中文版 access this enum in a different file e.g. MyClass.java. Do I use MyEnum.TWO, or what?


Exactly. You can do such:

MyEnum x = MyEnum.TWO;

Don't forget to import MyEnum if it is in another package.


Yes. for example:

MyEnum enumVar = MyEnum.TWO;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜