Without overriding
hashCode() you'll fine, until you do something that relies on it. Most likely, that will involve putting your objects in a
HashMap or
HashSet. Then it won't work quite as you expected. If you look at the documentation for
Object.equals() and
Object.hashCode() it explains how they are supposed to work.
I've got a couple of comments about your equals method:
1.
You should check
obj instanceof InstEqual before casting it, to avoid the possible exception. The should return false if the cast would fail.
2. Instead of:
it's easier to read if you just use: