I have a code block as follows :
public enum TierEnum {
Express,
Standard; // the semi-colon is redundant
}
Well in the code semi-colon(;
) is marked as redundant by the compiler. At the same time if I use
public enum TierEnum {
Express,
Standard
}; // again the semi-colon is redundant
Why in both the cases is the semi-colon marked redundant? How do I define the end of the list of enums in Java?
The terminating semicolon is needed if you add some code to the enum, like:
public enum TierEnum
{
Express( "Exp"),
Standard( "Std");
private String abbr;
private TierEnum( String aAbbr )
{
abbr = aAbbr;
}
public String getAbbr()
{
return abbr;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With