Below is the code that defines enum type.
enum Company{
EBAY(30), PAYPAL(10), GOOGLE(15), YAHOO(20), ATT(25);
private int value;
private Company(int value){
super(this.name());
this.value = value;
}
public int getValue(){
return value;
}
}
that gets internally compiled to,
final class Company extends Enum<Company>{
public final static Company EBAY = new Company(30);
public final static Company PAYPAL = new Company(10);
public final static Company GOOGLE = new Company(15);
public final static Company YAHOO = new Company(20);
public final static Company ATT = new Company(25);
private int value;
private Company(int value){
super(this.name(),Enum.valueOf(Company.class, this.name()));
this.value = value;
}
public int getValue(){
return value;
}
}
Is my understanding correct?
Functionally, yes. Literally no (you can't explicitly sub-class
Enum
for one thing).enum(s)
have atoString
. And yourenum
isn't valid code (you can't callsuper()
) andgetValue
needs a return type.