我想知道哪种方法更好地找到枚举的大小。
这种方式:
public enum Company {
AUDI(4), BMW(5), CADILLAC(11), FORD(44), JAGUAR(45);
private final int id;
public final int length = Company.values().length;
private Company(int id) {
this.id = id;
}
}
或者这样:
public enum Company {
AUDI(4), BMW(5), CADILLAC(11), FORD(44), JAGUAR(45);
private final int id;
public final int length = 5;
private Company(int id) {
this.id = id;
}
}