I have a class containing a static create method.
public class TestClass {
public static <E> TestClass<E> create() {
return new TestClass<E>();
}
}
when I use TestClass.create() , it can be compiled. But when I use TestClass<String>.create(), it failed to compile, how to specify the generic?
Assuming you are asking about specifying the type explicitly in case type inference fails, you can use
TestClass.<String>create()(notice how the type is after the.as opposed to before).