Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 741259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:36:43+00:00 2026-05-14T08:36:43+00:00

I have a problem when compiling a generic class with an inner class. The

  • 0

I have a problem when compiling a generic class with an inner class. The class extends a generic class, the inner class also.

Here the interface implemented:

public interface IndexIterator<Element>
    extends Iterator<Element>
{
  ...
}

The generic super class:

public abstract class CompoundCollection<Element, Part extends Collection<Element>>
    implements Collection<Element>
{
  ...

  protected class CompoundIterator<Iter extends Iterator<Element>>
      implements Iterator<Element>
  {
    ...
  }
}

The generic subclass with the compiler error:

public class CompoundList<Element>
    extends CompoundCollection<Element, List<Element>>
    implements List<Element>
{
  ...

  private class CompoundIndexIterator
      extends CompoundIterator<IndexIterator<Element>>
      implements IndexIterator<Element>
  {
    ...
  }
}

The error is:

type parameter diergo.collect.IndexIterator<Element> is not within its bound
       extends CompoundIterator<IndexIterator<Element>>
                                             ^

What is wrong? The code compiles with eclipse, but not with java 5 compiler (I use ant with java 5 on a mac and eclipse 3.5). No, I cannot convert it to a static inner class.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T08:36:43+00:00Added an answer on May 14, 2026 at 8:36 am

    The Java Language Specification, §8.1.3, defines the semantics of subclassing inner types as follows:

    Furthermore, for every superclass S of
    C which is itself a direct inner class
    of a class SO, there is an instance of
    SO associated with i, known as the
    immediately enclosing instance of i
    with respect to S. The immediately
    enclosing instance of an object with
    respect to its class’ direct
    superclass, if any, is determined when
    the superclass constructor is invoked
    via an explicit constructor invocation
    statement.

    Note that the enclosing instance is only described to be of a particular class, not a particular type. As all instances of a generic type share the same class, the following code would be legal:

    class Base<E> {
        E e;
    
        protected class BaseInner<I extends E>{
            E e() { return e; }
        } 
    } 
    
    class StrangeSub extends Base<Integer> {
        protected class StrangeSubInner extends Base<String>.BaseInner<String> {}
    }
    

    Of course, this can be used to break the type invariant (i.e. cause heap pollution):

        StrangeSub ss = new StrangeSub();
        ss.e = 42;
        String s = ss.new StrangeSubInner().e();
    

    The eclipse compiler takes the Java Language Specification as face value, and accepts the above code without even emitting an “unchecked” warning. While arguably technically compliant with the JLS, this clearly violates its intent.

    The Sun Java Compiler rejects the declaration of StrangeSubInner with:

    Test.java:32: type parameter java.lang.String is not within its bound
            protected class StrangeSubInner extends Base<String>.BaseInner<String> {}
                                                                           ^
    

    Apparently the compiler didn’t simply check the type parameter against inner’s super class’ type parameter bound like eclipse did. In this case, I believe this the right thing to do, as the declaration is clearly unsafe. However, the Sun compiler equally rejects the following declaration, even though it is provably type safe:

    class StrangeSub extends Base<Integer> {
        protected class StrangeSubInner extends BaseInner<Integer> {}
    }
    

    My hunch is that verifying the consistency of this diamond-shaped type restrictions is beyond the capabilities of the Sun compiler, and such constructs are therefore summarily rejected instead.

    To work around this limitation, I’d first try to get rid of the type parameter to CompoundIterator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is not pretty but it works: rm -R $(ls… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer Yes. Override the base1 and base2 methods in Derived to… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer No, you can't. Unfortunately, UIEvent doesn't expose any public way… May 16, 2026 at 12:45 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a problem compiling Haskell programs, that import the Text.Regex.Posix module. I have
I have started using of generics in Delphi 2010 but I have a problem
Scenario: I have a generic list of Audits and a generic list of AuditImages.
i have problem with maven. When i try to compile test classes ( mvn
I'm learning C++ and can't get my head around this problem: I have a
I have a problem with jQuqeryUI. I would like to run some code whenever
I have a design question concerning Django. I am not quite sure how to
I'm trying to find an elegant OOP solution for the following problem. Assume we
I'm working with Qt ( version 4.6 on Windows XP 32-bit and compiling in
I have a system where reservations are stored as records in one table(workshop_reservation) and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.