I have a Test class and its objects with same value (101,"abc") is created twice. I am inserting these two object in Hashmap as a Key. I want to understand the internal functioning as to why I am getting size as two of a map when both of my keys are same, it should probably overwrite ?
import java.util.HashMap;
import java.util.Map;
public class Test{
int id;
String name;
public static void main(String[] args) {
Test e1 = new Test(101,"abc");
Test e2 = new Test(101,"abc");
//Test e3 = new Test(101,"abc");
Map<Test, String> map = new HashMap<>();
map.put(e1, "XYZ");
map.put(e2, "CDF");
String value = map.get(e2);
System.out.println( "VALUE : "+value);
}
public Test(int id, String name) {
this.id = id;
this.name=name;
}}