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 8039975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:44:40+00:00 2026-06-05T03:44:40+00:00

I read about LinkedHashMap and from the description (although very interesting) I couldn’t understand

  • 0

I read about LinkedHashMap and from the description (although very interesting) I couldn’t understand how it actually does its job under the hood. As a side note, I know how a HashMap works underneath in Java.
So I review the source and still can not figure out how it works. Perhaps I am not grasping something fundamental in OOP in this case so bear with me.
To summarize the part that is confusing to me is the following:
The LinkedHashMap delegates all the calls to its parent HashMap.
Internally it overrides the HashMap.Entry to implement the various recordAccess and recordRemoval methods which seem to implement the logic of the LinkedHashMap
But the actual Entries are inside the table of the base class i.e. the HashMap which instantiates a table of HashMap.Entry and not of LinkedHashMap.Entry.
So I can’t figure out how the various recordAccess and recordRemove etc are actually being called.
So can anyone help me understand what’s going on here?
Am I correct to think that somehow the LinkedHashedMap.Entry is the type of table created by the HashMap? But how?

UPDATE:
My question is how do the recordAccess are being called. My experiment on this using a derived version of HashMap failed for the reason of Shengyuan Lu (+1) – My bad there

UPDATE:
The following which I tried is the same (I think) as what the LinkedHashMap is doing:

package delete;  

public class Base<T> {  

    Entry<T>[] table;  
    int idx = 0;  
    @SuppressWarnings("unchecked")  
    public Base(){  
        System.out.println("In base");  
        table = new Entry[10];  
    }

    public void add(T x){  
        table[idx] = new Entry(x);  
        table[idx].doSomething();  
    }  

    static class Entry<T>{  
        T value;  

        Entry(T x){  
            this.value = x;  
            System.out.println("Entry::Base");  
        }

        void doSomething(){  
            System.out.println("In Entry base, doing something");  
        }  
    }  

}  




public class Derived<T> extends Base<T> {  

    static class Entry<T> extends Base.Entry<T>{  

        Entry(T x) {  
            super(x);  
            System.out.println("In Entry derived");  
        }  

        int val;  

        @Override  
        void doSomething() {  
            System.out.println("In Entry derived doing something really smart!");  
        }       
    }  

    /**
     * @param args
     */
    public static void main(String[] args) {  

        Base<String> b = new Derived<String>();  
        b.add("Test string");  

    }  

}  

But it prints:

In base  
Entry::Base     
In Entry base, doing something    

So the derived Entry is never called.
Is my example different somehow? I can’t understand how this works for LinkedHashMap

  • 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-06-05T03:44:41+00:00Added an answer on June 5, 2026 at 3:44 am

    If you define MyLinkedHashMap under package java.util, it will compile;)

    Because HashMap.HashEntry is package visibility.

    PLUS:

    I think the major thing puzzled you is LinkedHashMap.Entry vs HashMap.Entry. The point is LinkedHashMap.Entry is-a HashMap.Entry. Actually HashMap.table stores LinkedHashMap.Entry in LinkedHashMap.

    Regarding to recordAccess and recordRemoval, they both override HashMap.Entry versions. You could find out the references both in LinkedHashMap and HashMap.

    Merge comments here: You sample code is not same as LinkedHashMap implementation. See LinkedHashMap.addEntry() instead.

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

Sidebar

Related Questions

I read about 'side effect' from this website : but still not understand why
Read about Server push here . I want to push data to client from
I read about Big-O Notation from here and had few questions on calculating the
Read about Fog: http://fog.io Does Python have anything like it? (a library for cloud
I read about skipList implementation in C++ and I don't understand this random function
I read about templated controls/INamingContainer but I can't understand what problem it solves when
I read about JSON from internet but still i have not got the grasp
I read about partial classes and, for example, I understand the reason for they
I've read about it, I understand it's basic function--I'd like to know an example
I read about __packed__ from here and, I understood that when __packed__ is used

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.