I think what you’re trying to do is simply not supported by Java generics. The simpler case of
public class Foo<T> {
public T<String> bar() { return null; }
}
also does not compile using javac.
Since Java does not know at compile-time what T
is, it can’t guarantee that T<String>
is at all meaningful. For example if you created a Foo<BufferedImage>
, bar
would have the signature
public BufferedImage<String> bar()
which is nonsensical. Since there is no mechanism to force you to only instantiate Foo
s with generic T
s, it refuses to compile.