Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java enum type instantiation

Tags:

java

enums

Are there any objects created respective to each of the enum constants ARROGANT, RASCAL, IDIOT?

public enum Manager {
    ARROGANT,
    RASCAL,
    IDIOT
}

and if the following code does the same as the above, explicitly though,

public enum Manager {
    ARROGANT(),
    RASCAL(),
    IDIOT();

    Manager() {}
}
like image 218
Shadab Avatar asked May 31 '11 10:05

Shadab


1 Answers

Yes, exactly one instance will be created for each enum constant.

And yes, the second sample code is effectively identical.

like image 189
Joachim Sauer Avatar answered Sep 18 '22 20:09

Joachim Sauer