Firstly null means non-existence of an instance. Providing a default constant like DEFAULT or NONE, will change that meaning. Secondly, why would you need something default to represent what seems to be non-existent? That is the purpose of null. Basically, you would have to initialize and store an extra object, which shouldn’t even exist whatsoever.
BTW, it’s not a language choice. It’s completely on you how you implement your enum. You can provide another constant like DEFAULT, or UNKNOWN in your enum, and avoid the assignment of null to the reference in your code. This is famously known as Null Object Pattern. But saying that the null assignment should itself be compiler error, then I would say, since an Enum is anyways compiled to a Class, so it would be perfectly valid to use null to represent non-existence of an instance.
One pitfall of allowing null though is with the usage of enum in switch-case. The below code will throw NPE, even with a default case:
public class Demo {
enum Color {
WHITE, BLACK;
}
public static void main(String[] args) {
Color color = null;
switch (color) { // NPE here
case WHITE: break;
case BLACK: break;
default: break; // null value does not fall into the default
}
}
}
Java does not allow a case null: either, producing the following compile error:
an enum switch case label must be the unqualified name of an enumeration constant