You can explicitly specify the type parameter when calling the method. For example:
<String>x("hello", "world");
However, if you do not explicitly specify a type parameter and rely only on a Java type inference function, I do not think that you can not only in Generics, but also in general.
The method parameter type is not a specific type, but rather something that denotes a set of applicable types (even this set can contain only one type, in the case of final classes, for example).
For example, this method:
public void x(Something a) { }
denotes a method that must have a type from a set of types that are compatible with Something (i.e., Something and all its subtypes).
The same goes for Generics.
Konstantin Yovkov May 13, '15 at 14:10 2015-05-13 14:10
source share