A picture is worth a thousand words. Images help to retain facts.
Here's an example.
Method equals() defines an elaborate contract (set of rules), as follows (straight from the Java API documentation):
1 It’s reflexive—For any non-null reference value x, x.equals(x) should return true. This rule states that an object should be equal to itself, which is reasonable.
2 It’s symmetric—For any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true. This rule states that two objects should be comparable to each other in the same way.
3 It’s transitive—For any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true. This rule states that while comparing objects, you shouldn’t selectively compare the values based on the type of an object.
4 It’s consistent—For any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified. This rule states that method equals() should rely on the value of instance variables that can be accessed from the memory and shouldn’t try to rely on values like the IP address of a system, which may be assigned a separate value upon reconnection to a network.
5 For any non-null reference value x, x.equals(null) should return false. This rule states that a non-null object can never be equal to null.
Do you think the following image would help you to retain the preceding set of rules in the exam?
Just scribble when you work with any topic while preparing for your exam. In the exam, you'll be able to recall those points with ease.
Ankit Garg wrote:Although the "we'll always love each other" might not apply very well on humans
Ha.. ha.. I agree. How about robots? But then they won't love each other!
Actually after I wrote that, I contradicted with my own statement. "we'll always love each other" statement should be "we'll always love each other, if you don't change" (as per the equals method contract). So the statement is true for humans too (as long as they don't change). But people change, so it's a paradox I guess