public enum itemType{
COMPANYY_WIDE("Company"),
DEPARTMENTAL("Departmental"),
PROJECT_SPECIFIC("Project");
private String itemCode;
private itemType(String dbCode){
this.itemCode=dbCode;
}
public static void main(String[] args) {
itemType type3=new itemType("Project");// line 1
itemType type2=itemType.valueOf("PROJECT_SPECFIFIC");// line 2
itemType type4=itemType.values()[0];// line 3
itemType type1=itemType.DEPARTMENTAL;
}
}
So enum itemType has 4 types and each type has an attribute itemcode which is also the dbcode. I try initializing the enum types with different approaches in main but I have some confusion. Why line 1 does not work? Why line 2 and line 3 will work?