No, there is no such syntax. Moreover, due to type erasure, the actual type T
not available at run time, so it would not be possible inside the general, even if the syntax were available.
The trick is to pass the Class<T>
along with other parameters and use reflection to get the method:
joinOnMethod(String separator, Collections<T> items, String methodName, Class<T> theClass)
Now you can request a class for the methodName
method and use this method in the calculations. This will not help you get away from passing strings (i.e., the Compiler will not cause an error if the method does not exist), but you can make it work with generics, despite the type being erased.
source share