I have an ArrayList:
List<MyClass> xxx = new ArrayList<MyClass>(functionThatGetsAList());
When I test xxx.size()
I get 3, which is right. Then I try to cast:
Set<MyClass> yyy = new HashSet<MyClass>(xxx);
or alternatively:
Set<MyClass> yyy = new HashSet<MyClass>();
yyy.addAll(xxx);
In both cases yyy.size()
is 1 and it only copies the first object. Why?