Roedy Green <see_w...@mindprod.com.invalid> wrote:
> On Mon, 18 Feb 2013 12:29:53 -0800 (PST), Lew <
lewb...@gmail.com>
> wrote, quoted or indirectly quoted someone who said :
>> The diamond operator distinguishes the generics usage.
> OK, that is obvious, but would it break any code?
I'm not taking the time to think it all through to the end,
but "fwiw":
To see any technical difference between the two patterns:
Base<Type> b = new Sub<>();
and
Base<Type> b = new Sub();
You might want to consider different subclasses of some class,
where one is itself generic and the other is not:
interface Base<T> { ... }
class Sub1<T> implements Base<T> { ... }
class Sub2 implements Base<String> { ... }
Most likely(*), it is currently *not* legal to write:
Base<String> b = new Sub2<>();
So, the compiler probably shouldn't *always* assume the <>
to a pattern like: Base<Type> b = new SubClass();
In how far it would be always possible for the compiler to
check the referenced class first (to see if it is generic
and if so then just assume the diamond), I can't tell.
PS:
*: I did not care enough to check the JLS or even try it.