Generics: Unrecognizable extension of static innerclass after genericizing its outer


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Generics: Unrecognizable extension of static innerclass after genericizing its outer

  1. #1
    Join Date
    Dec 2005
    Posts
    3

    Generics help!! -- extending static inner classes

    I have a set of classes coded as defined here.

    Code:
    1   //A.java:
    2   public class A<T extends SomeArbitraryClass<T>> extends AnotherArbitraryClass<T> {
    3   
    4     public static class B {
    5 
    6       protected void set(C val) { ... }
    7
    8       protected class C { ... }
    9     }
    10  }
    11
    12  //ObjThatExtendsB.java
    13  public class ObjThatExtendsB extends A.B {
    14
    15    protected void doSomeSetting() {
    16      super.set(new ObjThatExtendsC());       //compile error is on this super.set() call.
    17    }
    18
    19    protected class ObjThatExtendsC extends C { ... }
    20  }
    This code worked before applying generics to line 2. But, now, I get this compiler error on line 16:
    The method set(A<T>.B.C) in the type A.B is not applicable for the arguments (ObjThatExtendsB.ObjThatExtendsC).

    I speculate that there is a problem in the way I extend A.B on line 13. I have tried to play with the ObjThatExtendsB class signature to attempt to pass along a generic type as follows:

    Code:
    public class ObjThatExtendsB<T extends SomeArbitraryClass<T>> extends A<T>.B 
    { ... }

    But, this produces the following error:
    The member type A<T>.Iteratorable cannot be qualified with a parameterized type, since it is static. Remove arguments from qualifying type A<T>.

    Now, since it seems impossible to pass the type along in the ObjThatExtendsB class signature, on line 13, then how else would I be able to successfully cast my new ObjThatExtendsC(), on line 16, as an A<T>.B.C as the original compiler error msg seems to suggest?

    Or, how else could I change the class signatures of ObjThatExtendsB or ObjThatExtendsC to get A.set(A.B.C) to recognize ObjThatExtendsC as an extension of A.B.C?

    Any help is appreciated. Thanks for your time!
    Last edited by sfrancolla; 12-21-2005 at 02:52 PM. Reason: enhance the title

  2. #2
    Join Date
    May 2005
    Posts
    75
    Java doesn't let you extend more than one class.

    I'm not clear on exactly what you're trying to do, however, one possibility is to create a second class that extends AnotherArbitraryClass<T>, and then create an object of that class.
    Last edited by srekcus; 12-21-2005 at 02:54 PM.

  3. #3
    Join Date
    Dec 2005
    Posts
    3
    To give it a bit of context, class A has an inner class, B, that manages an iterator wrapper, C. B is in charge of extracting iterators from unconventional collection types ("collection-esque" objs that don't necessarily extend collection) and wrapping them with C to allow for customization of the iterator's entries. A calls iterator() on B to get C, the wrapped iterator, and goes from there.

    The way it's written, C is protected within B. So, to customize C, B must be extended; within which, C is extended. Then, the new wrapper (ObjThatExtendsC) is set into B by passing it up via the super.set(C) call.

    The error I get basically says that, because of generics on A, set(<@attrib of type C>) doesn't work where the attrib is an object that extends C and is defined outside of A... as it is above.

    I am specifically interested in why applying generics to A make this implementation not possible because it worked beforehand.

    Any ideas on that? Thanks.


    Quote Originally Posted by srekcus
    Java doesn't let you extend more than one class.

    I'm not clear on exactly what you're trying to do, however, one possibility is to create a second class that extends AnotherArbitraryClass<T>, and then create an object of that class.

  4. #4
    Join Date
    Dec 2005
    Posts
    3
    I was able to solve this at last. The Eclipse compiler erroneously misunderstands the relationships between these generic classes/methods. Compiling outside of Eclipse using Sun 1.5.0_05 produces no errors.


    Thanks all for the suggestions.

    Steve

Similar Threads

  1. Trouble buffering transparent gif
    By axlan in forum Java
    Replies: 2
    Last Post: 06-22-2005, 08:21 AM
  2. private and static
    By Mark in forum Java
    Replies: 3
    Last Post: 06-09-2000, 08:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center