This discussion is archived
1 Reply Latest reply: Feb 14, 2012 11:11 AM by DrClap RSS

Nested Generics

917452 Newbie
Currently Being Moderated
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
    DrClap Expert
    Currently Being Moderated
    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>>


  • Correct Answers - 10 points
  • Helpful Answers - 5 points