If you have a Java enum and a variable of the enum's type, as so:
public enum Something
{
VAL1,
VAL2,
VAL3
}
public Something varName;
why is it necessary to write varName = Something.VAL1; instead of simply varName = VAL1;? Shouldn't the compiler know from the type of varName that it can only take null, VAL1, VAL2, and VAL3 as values?
Somethingimplements an interface (Serializable, for example), and you want to declarevarNameas aSerializable. How would the compiler know that you are trying to declare from that particular enum, versus any other serializable type? The language is designed to allow a variable to be typed as any of its supertypes, and this wouldn't be possible with your suggested enum declaration style.