public class Bar<T> { } public class Foo <T> { private final Bar<T>[] ts; public Foo(Bar<T>[] ts) { this.ts = ts; } public Bar<T> getT(int i) { return ts[i]; } public static Foo<String> createStringInstance() { return new Foo<String>(new Bar|); } }
Press Ctrl-Shift-Space at the caret (|) and you will get a compile time error:
public class Foo <T> { ... public static Foo<String> createStringInstance() { return new Foo<String>(new Bar<String>[0]); } }