April 2018
Intermediate to advanced
910 pages
33h 21m
English
Enhanced enums will augment the expressiveness of the enum construct in the Java Language by allowing type-variables in enums (generic enums), and performing sharper type-checking for enum constants. (http://openjdk.java.net/jeps/301). What this means is that enums will finally support a parameterized type, allowing something like this (taken from the JEP at the link mentioned previously):
enum Primitive<X> { INT<Integer>(Integer.class, 0) { int mod(int x, int y) { return x % y; } int add(int x, int y) { return x + y; } }, FLOAT<Float>(Float.class, 0f) { long add(long x, long y) { return x + y; } }, ... ; final Class<X> boxClass; final X defaultValue; Primitive(Class<X> boxClass, X defaultValue) { this.boxClass = boxClass; ...