I was looking at some of the core language enhancements being considered for JDK 7.  Some of them look pretty good, others, meh.  Here are a few of the ones I’m looking forward to:

Constructor Inference for Generics

Using generics, your currently have to type both sides of an assignment when doing a constructor:

Map<String, List<String>> anagrams = new HashMap<String, List<String>>();

Being considered is the ability to omit the types and infer them, such as:

Map<String, List<String>> anagrams = new HashMap<>();

which would be equivalent to the first line.  I like this - improves readability, loses nothing but typing.

Relational operators for Enums

Currently, the only relational operators that you can use for constants in an Enum are == and !=.  Since all enums implicitly implement Comparable, theres no good reason why you should not be able to use <, >, <= and >= on enums.  As it stands now, you need to explicitly invoke compareTo().

Switches on Strings

Sure would be nice if instead of if-else if-else constructs to branch on string values, you could do

switch(someString) {
   case CONST_1:
      return true;
   case CONST_2:
      return false;
   default:
      throw new IllegalArgumentException("Bad value: " + s);
}
Leave a Reply