The following code does not compile, because Java cannot infer the type parameter to getSomething:
class Example {
static void callIt() {
takeString(getSomething());
}
static void takeString(String s) {
}
static <T> T getSomething() {
return null;
}
}
Is there some way to specify the type parameter like <String>getSomething(), but without specifying the name of the class it is being called on? i.e. not Example.<String>getSomething().
Is there some way to specify the type parameter like
<String>getSomething(), but without specifying the name of the class it is being called on? i.e. notExample.<String>getSomething()
No, there is not. That is the syntax for explicitly providing a type argument to a generic method.
Your code should compile on Java 8, with its improved and targeted type inference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With