Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging HashMap shows a recursive entrySet? What is it?

Tags:

java

hashmap

I am using an HashMap<String,Serializable> and while debugging I see the following recursively. What does that mean? Why is it so?

enter image description here

like image 576
vivek_jonam Avatar asked Dec 21 '22 06:12

vivek_jonam


2 Answers

HashMap$EntrySet is a inner class, it has an explicit reference called this$0 to the HashMap. And the HashMap has a field private transient Set<Map.Entry<K,V>> entrySet which refers to it. So, just usual cyclic references.

like image 132
kan Avatar answered Feb 11 '23 14:02

kan


The HashMap instance has a field entrySet with the type HashMap$EntrySet. Since the EntrySet class is an inner class of HashMap, it has an implicit reference to the containing instance (this$0).

This is normal and required for the EntrySet instance to access the containing HashMap instance.

like image 43
jarnbjo Avatar answered Feb 11 '23 15:02

jarnbjo