A
aaronfude
Enums and type safety are obviously a great idea, but in one instance
there seems to be more typing or am I wrong?
class Pet {
enum Type { DOG, CAT, SNAKE };
String name;
public Pet(Type type, String name) {
//
}
}
Then when calling:
Pet pet = new Pet(Pet.Type.DOG, "Sparky");
With the old ugly final ints it was
Pet pet = new Pet(Pet.DOG, "Sparky");
Am I wrong or is it in fact more typing when refurring to the enums
from outside the class?
Thanks!
Aaron
there seems to be more typing or am I wrong?
class Pet {
enum Type { DOG, CAT, SNAKE };
String name;
public Pet(Type type, String name) {
//
}
}
Then when calling:
Pet pet = new Pet(Pet.Type.DOG, "Sparky");
With the old ugly final ints it was
Pet pet = new Pet(Pet.DOG, "Sparky");
Am I wrong or is it in fact more typing when refurring to the enums
from outside the class?
Thanks!
Aaron