Suppose you have a generic class
class MyClass<T> { ... }
You can force T
to extend or implement a class or an interface, respectively, by writing
class MyClass<T extends ThisClassOrThisInterface> { ... }
You can even make this construction fully parametric, by abstracting on ThisClassOrThisInterface
, namely
class MyClass<U, T extends U> { ... }
My question is: Is there a way to force T
to be a parameterized type? For instance, in a way that
class AnotherClass extends MyClass<List<?>>
shall be fine, because List
is a generic type, but
class AnotherClass extends MyClass<Object>
shall not, because Object
cannot be parameterized over any type.
I was trying to understand how much you can play with generics. In particular, I was trying to implement the following class (pretend that <T<?>>
forces T
to be a generic type):
class MyClass<T<?>> {
<A> Function<A, T<A>> myMethod() { ... }
}