I have an odd conceptual question, It's not about a specific incident, just a general best-practices approach.
I have asked myself on occasion when defining java Equal methods, what makes two objects equal. The simple approach is to check rather every field is equal, however, there are occasions when this isn't always logical. Here are three examples I could think of when I'm not certain rather a field should be part of an equals method:
transient fields and state data. Any transient field on a JPA object for example. or say I have a plugin class with a jar location and some other identification data to uniquely define where to find a plugin to load, and a transient isLoaded Boolean which tells me rather I got around to loading the plugin yet. Should two references to the same plugin but with different isLoaded variables be equal?
Costly equality checks. Lets say I have a person that has a family members array. If I check everyone in the family member array I have to check everyone in their array etc and suddenly my equality method checks every person in memory, and has to check for cycles etc.
Data that may not be loaded at time of equality check. Lets say I have a JPA object with consists of only two fields, a unique Name, and a UUID field generated by the database. The name uniquely identifies the row of the database, but the UUID only exists when I load from the database. How do I check if an Object I want to save to the database is equal to the ones I already loaded to the database, does the fact that one object doesn't have the UUID that is generated by the database make them unique etc?
I realize that at times it depends on how you plan to use the quality method. However, in situations where you are writing an object and aren't yet certain how it will be utilized how do you decide what to include in an equal method? Do you never overwrite one unless you can include every field in the check?
If you need your hash function to behave in a certain manner, which indirectly defines how your equality method should work, but someone could easily assume a different definition of equality does this mean you simply need to notate your equal method well, or is it a code smell that you have done something wrong?