I just thought I was adding that when implementing the equals method in your code, you also have to implement (override) the hashCode method. This is a general contract that you must follow for the best performances.
Below are excerpts from the Joshua Bloch book "Effective Java"
Item 9: Always override hashCode when you override equals
A common source of bugs is the failure to override the hashCode method. You must override hashCode in every class that overrides equals. Failure to do so will result in a violation of the general contract for Object.hashCode, which will prevent your class from functioning properly in conjunction with all hash-based collections, including HashMap,HashSet, and Hashtable. Here is the contract, copied from the Object specification [JavaSE6]: โข Whenever it is invoked on the same object more than once during an execution of an application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. โข If two objects are equal according to the equals(Object) method, then calling the hashCode method on each of the two objects must produce the same integer result.
And, as Pablo said, if you use anything other than the Object class in your signature of the equals method, you will not actually override the equals method, and your program will not work properly.
Take, for example, this small program that copies a List to Set (which cannot contain duplicates) and prints a new collection. Try replacing equals(Object obj) with equals(Item obj) and see what happens when the program starts. Also, comment out the hashCode() method and run the program and notice the difference between its use and not.
public class Item { private String name; private double price; private String countryOfProduction; public Item(String name, double price, String countryOfProduction) { this.setName(name); this.setPrice(price); this.setCountryOfProduction(countryOfProduction); } public String getName() { return name; } public void setName(String name) { this.name = name; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public String getCountryOfProduction() { return countryOfProduction; } public void setCountryOfProduction(String countryOfProduction) { this.countryOfProduction = countryOfProduction; } public String toString() { return "Item Name: " + getName() + "\n" + "Item Price: N" + getPrice() + "\n" + "Country of Production: " + getCountryOfProduction() + "\n"; } @Override public boolean equals(Object obj) { if(!(obj instanceof Item)) { return false; } if(obj == this) { return true; } Item other = (Item)obj; if(this.getName().equals(other.getName()) && this.getPrice() == other.getPrice() && this.getCountryOfProduction().equals(other.countryOfProduction)) { return true; } else { return false; } } public int hashCode() { int hash = 3; hash = 7 * hash + this.getName().hashCode(); hash = 7 * hash + this.getCountryOfProduction().hashCode(); hash = 7 * hash + Double.valueOf(this.getPrice()).hashCode(); return hash; } public static void main (String[]args) { List<Item> items = new ArrayList<>(); items.add(new Item("Baseball bat", 45, "United States")); items.add(new Item("BLUESEAL Vaseline", 1500, "South Africa")); items.add(new Item("BLUESEAL Vaseline", 1500, "South Africa")); Collection<Item> noDups = new HashSet<>(items); noDups.stream() .forEach(System.out::println); } }