HashSet and object identity

Report a typo

How many elements does this HashSet have when hashcode() and equals() are properly overridden to store only unique elements?

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

    Set<Person> set = new HashSet();
    set.add(james);
    set.add(james);
    set.add(new Person("James Gosling"));

    System.out.println(set.size());
Enter a number
___

Create a free account to access the full topic