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;
精彩评论