1 Reply Latest reply: Feb 14, 2012 1:11 PM by DrClap RSS

    Nested Generics

      I'm trying out this generics example and I cannot get it to compile.

      Here's the error msg:
      Bound mismatch: The type SubB<SubA> is not a valid substitute for the bounded parameter <T extends B<? super A>> of the type X<T>

      class A {

           class SubA extends A {

           class B<T extends A> {

           class SubB<T extends A> extends B<T> {

           class X<T extends B<? super A>> {

      new X<SubB<SubA>>(); // compilation error
        • 1. Re: Nested Generics
          SubB extends B... check. SubA is a superclass of A... nope.

          If your goal is simply to write some code which compiles (and I don't see any other possible purpose for that code) then try declaring X like this:
          class X<T extends B<? extends A>>