這是什麼之間的區別:EnumMap的與枚舉值
public enum Direction {
NORTH(90),
EAST(0),
SOUTH(270),
WEST(180);
private final int degree_;
private Direction(int degree) {
degree_ = degree;
}
public int getDegree() {
return degree_;
}
public static void main(String[] args) {
System.out.println(NORTH.getDegree());
}
}
這:
public enum Direction {
NORTH,
EAST,
SOUTH,
WEST;
public static void main(String[] args) {
EnumMap<Direction, int> directionToDegree = new EnumMap<Direction, int>(Direction.class);
directionToDegree.put(NORTH, 90);
directionToDegree.put(EAST, 0);
directionToDegree.put(SOUTH, 270);
directionToDegree.put(WEST, 180);
System.out.println(directionToDegree.get(NORTH));
}
}
是一個更容易閱讀?更靈活嗎?傳統上使用更多嗎?一個人跑得快嗎?任何其他利弊?
爲什麼財產「有界」?這是「保稅」的錯字嗎?不挑剔,好奇。 – Thufir
@Thufir:謝謝,這是一個錯字 –
大聲笑,我以爲有一些特別的意思:)我在想上下界..等等 – Thufir