Qual è la differenza tra questo:EnumMap vs. Enum valori
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());
}
}
e questo:
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));
}
}
È uno più facile da leggere? È uno più flessibile? Uno è usato più convenzionalmente? Si corre più veloce? Qualche altro pro e contro?
perché la proprietà è "limitata"? È un errore di battitura per "incollato"? Niente pignoli, curioso. – Thufir
@Thufir: grazie, è stato un errore di battitura –
LOL, ho pensato che ci fosse un significato speciale :) Stavo pensando ai limiti superiore e inferiore..etc – Thufir