我正在尝试制作一个简单的脚本来返回枚举的值,让我们举个例子://EG.class(应该返回动物 ID。
import Object.Animal;
public class EG {
public void main() {
Animal AnimalID = Object.Animal.CAT;
System.out.print(AnimalID);
//Should return value of CAT: 2000 (long)
//But I can't figure out what's wrong.
}
}
//对象.类
public class Object {
public enum Animal {
CAT(2000L), DOG(2001L), MONKEY(2002L), TIGER(2003L);
private long animal;
private Animal(long a) {
animal = a;
}
public long getAnimal() {
return animal;
}
}
}