A Java method call may be parameterized like in the following code:
class Test
{
<T> void test()
{
}
public static void main(String[] args)
{
new Test().<Object>test();
// ^^^^^^^^
}
}
I found out this is possible from the Eclipse Java Formatter settings dialog and wondered if there are any cases where this is useful or required.
EDIT
Based on Arne's excellent answer i came up with the following conclusion:
In addition to improved type safety as Arne's example illustrates a parameterized method call enables you to specify the common base type of the methods arguments that should be the type of the container elements. This type is normally inferenced automatically by the compiler to the most specific common base type. By parameterizing the method call this behaviour may be overridden. A parameterized method call may be required if there are multiple common types inferenced by the compiler.
The following example demonstrates that behaviour:
import java.util.Arrays;
import java.util.List;
class Test
{
public static void main(String[] args)
{
Integer a=new Integer(0);
Long b=new Long(0);
List<Object> listError=Arrays.asList(a, b);
//error because Number&Comparable<?> is not Object
List<Object> listObj=Arrays.<Object>asList(a, b);
List<Number> listNum=Arrays.<Number>asList(a, b);
List<Comparable<?>> listCmp=Arrays.<Comparable<?>>asList(a, b);
}
}
This behaviour is defined in The Java Language Specification Third Edition paragraphs 8.4.4 and 15.12.2.7 but not easily understood.