To use a contrived example in Java, here's the code:
enum Commands{
Save("S");
File("F");
private String shortCut;
private Commands(String shortCut){ this.shortCut = shortCut; }
public String getShortCut(){ return shortCut; }
}
I have the following test/driver code:
public static void main(String args[]){
System.out.println(Commands.Save.getShortCut());
}
The question is:
In Java, when is the constructor for an enumerated constant invoked? In the above example, I am only using the Save
enumerated constant. Does this mean that the constructor is called once to create Save
only? Or will both Save
and File
be constructed together regardless?