这有什么区别:
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));
}
}
更容易阅读吗?一种更灵活吗?一个更传统地使用吗?一个人跑得更快吗?还有其他优点和缺点吗?