paolo@bimodesign.com | +34 608 61 64 10

Java

        

Java - Enums with values

Enums are classes in Java. They have an implicit ordinal value, starting at 0. If you want to store an additional field, then you do it like for any other class:

public enum ClassEnum {

	ONE(1, "One"), 
	TWO(2, "Two"),
	THREE(3, "Three"),
	FOUR(4, "Four"),
	FIVE(5, "Five");

	private int code;
	private String name;

	private ClassEnum(int code, String name) {
		this.code = code;
		this.name = name;
	}

	public int getCode() {
		return code;
	}

	public String getName() {
		return name;
	}
}