My point is that with val, Java won't be able to infer the generic type on the right side of the expression. You'll now have to define it, whereas you wouldn't with diamond, so long as the left side is explicit.
Using val will reduce the number of characters, but not by as much as you might think for objects with generics.
I'd argue that the diamond is not so narrow a use case as you might think, too, and that val hurts readability by making the left side non-explicit. Those are purely opinion, though.
Last time I wrote a Java application, I didn't use <> once. The trivial amount of time savings it offered didn't justify the mental energy to remember it existed.
Most IDEs should autocomplete to the diamond, so it's hardly something you use consciously. I know it exists, and my code ends up using it, but I rarely have to actively make an effort.
6
u/depressiown Mar 09 '16
My point is that with val, Java won't be able to infer the generic type on the right side of the expression. You'll now have to define it, whereas you wouldn't with diamond, so long as the left side is explicit.
Using val will reduce the number of characters, but not by as much as you might think for objects with generics.
I'd argue that the diamond is not so narrow a use case as you might think, too, and that val hurts readability by making the left side non-explicit. Those are purely opinion, though.