Mutation trick in HashMap

Report a typo

What is the output of this application?

Note that it doesn't matter if hashCode() or equals() are overridden or not. You will get the same result.

    Person james = new Person("James Gosling");

    Map<Person, Integer> map = new HashMap();
    map.put(james, 1995);

    james.setName("J. Gosling");

    System.out.println(map.get(new Person("J. Gosling")));
Enter a short text
___

Create a free account to access the full topic