I have the following code -
Collection collection1 = new ArrayList();
collection1.add(new Integer(1));
Collection collection2 = new ArrayList();
collection2.add(new Integer(1));
Integer integer = new Integer(1);
System.out.println(collection1.equals(collection2));
System.out.println(collection1.equals(integer));
Output -
true
false
The result is as expected. But then shouldn't the Collection Interface method be - boolean equals(Collection c)
?
But, instead it is boolean equals(Object obj)
So how can it be that a non Collection Object can be successfully passed as parameter to get boolean output true?