JDK 1.7 Features
Diamond Operator - If we have to declare a map of trades using Generics, we write the code as follows: Map<String, List<Trade>> trades = new TreeMap<String, List<Trade>> (); The not-so-nice thing about this declaration is that we must declare the types on both the sides, although the right-hand side seems a bit redundant. Can the compiler infer the types by looking at the left-hand-side declaration? Not unless you’re using Java 7. In 7, it’s written like this: Map<String, List<Trade>> trades = new TreeMap <> (); How cool is that? You don’t have to type the whole list of types for the instantiation. Instead you use the symbol, which is called diamond operator. Note that while not declaring the diamond operator is legal, as trades = new TreeMap (), it will make the compiler generate a couple of type-safety warnings. Using String Swith in Statement witch statements work either with primitive types or enumerated types. ...