This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am using an ArrayList to store my CustomQuery objects. I am using .contains(customQuery) to compare weather the object is already present or not? If it's not there I am adding the object to the list.
The problem is list.contains(customQuery) always return false, even if the objects are equal(i.e. their id's are equal). I've also overrided .equals() and .hascode() method in my CustomQuery class.
1) what will happen if I pass a String into the equals method? It will certainly compile.
2) do you really need a List? A Set makes sure of uniqueness; if the order is important then a LinkedHashSet will work as well.