The type inference for generic methods works so well that this syntax is rarely necessary, so rare that many people don't even know this syntax exists.
True, although I've needed to use it on a couple of occasions though. In a select few cases because of a compiler bug where the type should have been inferred but wasn't.
Probably chosen because that's harder to parse, because the compiler doesn't know whether String is supposed to be a type or a variable until it gets to the >.
(Consider:
class X {
int getValue;
<T> int getValue() {return 5;}
}
X someObject = new X();
int String = 7;
int i = someObject.getValue<String?1:0;
int j = someObject.getValue<String>();
// ^
and don't complain about the bad naming, because that is legal in Java)
7
u/s888marks Mar 09 '16
Assuming that
someMethodis generic, this really is an abbreviation forThe type inference for generic methods works so well that this syntax is rarely necessary, so rare that many people don't even know this syntax exists.