I'm reading Effective Java 3 and noticed this code in Item 43: “Prefer method references to lambdas”:
TreeMap<K,V>::new
Notice the type parameters. I've always just done:
TreeMap::new
I use Intellij and have never gotten a warning about this or any recommendation to change it. In fact, when I have the IDE change the above method reference into a lambda it converts it to
() -> new TreeMap<Integer, Integer>()
What is the value in including the type parameters? Can't the compiler infer it based on the type parameters of the variable? Based on how the IDE transformed the method reference into a lambda it seems like it can.