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

  • SEARCH
  • Home
  • 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 6064463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:17:00+00:00 2026-05-23T09:17:00+00:00

A peer at work has extended LinkedHashMap, and overridden removeEldestEntry similar to: import java.util.LinkedHashMap;

  • 0

A peer at work has extended LinkedHashMap, and overridden removeEldestEntry similar to:

import java.util.LinkedHashMap;
import java.util.Map.Entry;

public class CompileTest {
    static class MyMap<K, V> extends LinkedHashMap<K, V> {
        protected boolean removeEldestEntry(Entry<K, V> eldest) {
            return true;
        }
    }
}

Notice the parameter class is Entry, not Map.Entry.
Eclipse generated the method signature. IntelliJ shows an error complains that Entry has private access in java.util.LinkedHashMap, and prefers Map.Entry. But it still compiles either way.

I wrote a smaller example to experiment:

public class CompileTest {

    static class A{
        public class Inner {
        }

        public void doStuff(Inner a){}
    }

    static class B extends A{
        private class Inner {
        }
    }

    static class C extends B {
        public void doStuff(Inner a) { }
    }
}

Now IntelliJ does not show an error, but the class fails to compile. Here are 2 situations that seem the same, where both the IDE and the compiler seem to alternate behaviors and also never agree with each other.

Can someone explain this?

  • 1 1 Answer
  • 0 Views
  • 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-23T09:17:00+00:00Added an answer on May 23, 2026 at 9:17 am

    From the Java Language Specification – 8.5 Member Type Declarations

    If the class declares a member type
    with a certain name, then the
    declaration of that type is said to
    hide any and all accessible
    declarations of member types with the
    same name in superclasses and
    superinterfaces of the class.

    A class inherits from its direct
    superclass and direct superinterfaces
    all the non-private member types of
    the superclass and superinterfaces
    that are both accessible to code in
    the class and not hidden by a
    declaration in the class.

    We can deduce that:

    B.Inner hides A.Inner. B does not inherit A.Inner. A.Inner is not a member(8.2) type of B. C cannot inherit A.Inner from B. C cannot inherit B.Inner from B because it’s private.

    Therefore C does not have a member type Inner. Assume there is no other Inner type in C’s enclosing scopes (outer class; compilation unit; package), then type name Inner cannot be resolved.

    javac tries to report a more detailed error, but that’s only a guess at your intention. An even better error message probably should include all the above explanations.

    In the 1st example about Entry, the import statement declares Entry in the entire compilation unit scope(i.e. the java file), therefore Entry is resolved to be Map.Entry

    IntelliJ 10.5 doesn’t complain about the 1st example; apparently the bug has been fixed. It is still wrong on the 2nd example.

    There is something funny about private. Why does the spec explicitly exclude private members while it already requires members be “accessible”? Actually B.Inner is accessible in the entire body of CompileTest (6.6.1), including C. C can have a doStuff(B.Inner) and it will compile.

    That’s probably why IntelliJ screws up on the 2nd example; it thinks that B.Inner is accessible to C, therefore C inherits B.Inner. It overlooked the extra exclusion clause of private members in inheritance.

    This reveals 2 conflicting views on the scope of a private declaration. View #1 wants the scope to be the immediate enclosing class, view #2 wants it to be the top level enclosing class. #2 is less known by programmers, they’d be surprised to learn that C can access B.Inner. #2 can be justified in the following way: they are all in the same file anyway, so there’s no need for encapsulation, we aren’t protecting anyone by prohibiting the access; allowing access is more convenient in most use cases.

    View #2 probably also argued that C should inherit B.Inner – what could go wrong? Interestingly #2 wins on the general access control rule, but lost on the inheritance rule.

    The spec is really really messy, fortunately we usually don’t run into these complicated situations. It is rather the fault of LinkedHashMap and HashMap that repurpose a public name for private use.

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

Sidebar

Related Questions

I write an (Java-) application that streams a video from one peer to another.
I'm doing a peer review and I've found people using window.location.search to check what
Flash 10+ allows peer to peer capabilities to be implemented in Flex and Flash
We use SVN at work (ie. this is not an open-source project) and have
I'm making a small peer-to-peer app that holds a common collection of objects. This
I'm kinda a newbie at regular expressions, so would appreciate a bit of peer
SDK level 8 (Froyo) has introduced the native capability for the MediaPlayer to connect
I would like to get some tips from peer developers about how you go
I have a symfony module for my GenericImport class. Rather than the default method
I'm trying to secure a connection from a Java Client/Server application that communicates over

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.