| 1 | What is the default behavior of equals() and hashCode() inherited from Object, and why is it usually necessary to override them for value-based classes? Java › equals(), hashCode() & toString() Contracts | Java | equals(), hashCode() & toString() Contracts | Beginner |
| 2 | What are the five formal properties an equals() implementation must satisfy according to its documented contract (reflexive, symmetric, transitive, consistent, and null-handling)? Java › equals(), hashCode() & toString() Contracts | Java | equals(), hashCode() & toString() Contracts | Intermediate |
| 3 | How does Objects.equals() and Objects.hash() from java.util.Objects simplify writing correct equals() and hashCode() implementations, particularly regarding null-safety? Java › equals(), hashCode() & toString() Contracts | Java | equals(), hashCode() & toString() Contracts | Intermediate |
| 4 | What is the relationship between equals() and the == operator when comparing primitive types versus reference types, and how does this affect comparing boxed wrapper types like Integer? Java › equals(), hashCode() & toString() Contracts | Java | equals(), hashCode() & toString() Contracts | Intermediate |
| 5 | How would you write a unit test that thoroughly verifies a custom equals() and hashCode() implementation satisfies its contract, and what testing libraries exist specifically for this purpose? Java › equals(), hashCode() & toString() Contracts | Java | equals(), hashCode() & toString() Contracts | Intermediate |
| 6 | How does Comparable's compareTo() method relate to equals(), and what does it mean for compareTo() to be 'consistent with equals'? Java › equals(), hashCode() & toString() Contracts | Java | equals(), hashCode() & toString() Contracts | Intermediate |
| 7 | Why is it particularly important for a class's equals() and hashCode() to be based on effectively immutable data specifically when that class is used as a JPA/Hibernate entity, and what special considerations apply to entity identity before it's persisted (has a generated ID)? Java › equals(), hashCode() & toString() Contracts | Java | equals(), hashCode() & toString() Contracts | Intermediate |
| 8 | How does the getClass() versus instanceof choice in an equals() implementation affect whether subclasses can be considered equal to their superclass instances, and what's the Liskov Substitution Principle tension involved? Java › equals(), hashCode() & toString() Contracts | Java | equals(), hashCode() & toString() Contracts | Advanced |
| 9 | Why must hashCode() be overridden whenever equals() is overridden, and what specific, hard-to-diagnose bugs occur in a HashMap when this contract is violated (equals() overridden but hashCode() left as default)? Java › equals(), hashCode() & toString() Contracts | Java | equals(), hashCode() & toString() Contracts | Advanced |
| 10 | How does Java Record's automatically-generated equals(), hashCode(), and toString() implementations work, and in what specific ways do they differ from a manually-written, field-by-field implementation? Java › equals(), hashCode() & toString() Contracts | Java | equals(), hashCode() & toString() Contracts | Advanced |
| 11 | How would you implement equals()/hashCode() correctly for a class containing a mutable field, and why does using such a class as a HashMap key or HashSet element create a serious risk? Java › equals(), hashCode() & toString() Contracts | Java | equals(), hashCode() & toString() Contracts | Advanced |
| 12 | How would you correctly implement equals() and hashCode() for a class in an inheritance hierarchy where the superclass itself defines meaningful equality-relevant fields, without breaking the contract when subclasses add their own fields? Java › equals(), hashCode() & toString() Contracts | Java | equals(), hashCode() & toString() Contracts | Advanced |
| 13 | How would you use Lombok's @EqualsAndHashCode and @ToString annotations to eliminate equals()/hashCode()/toString() boilerplate, and what specific configuration options handle inheritance and field exclusion correctly? Java › equals(), hashCode() & toString() Contracts | Java | equals(), hashCode() & toString() Contracts | Advanced |
| 14 | What is the difference between the == operator and the .equals() method when comparing two custom objects, if the class hasn't overridden equals()? Java › Java Fundamentals: Syntax, Data Types & Operators | Java | Java Fundamentals: Syntax, Data Types & Operators | Beginner |
| 15 | What is the contract between equals() and hashCode() that a custom class must satisfy to work correctly as a HashMap key or HashSet element? Java › Collections Framework | Java | Collections Framework | Intermediate |
| 16 | What is the difference between the == operator and the .equals() method when comparing String objects, and why does String's string pool (interning) behavior sometimes make == appear to 'work' for strings? Java › Java Fundamentals: Syntax, Data Types & Operators | Java | Java Fundamentals: Syntax, Data Types & Operators | Intermediate |
| 17 | What is the difference between reference equality (==) and value equality (Equals()) for a reference type by default? C# › Equality: Equals, GetHashCode & IEquatable | C# | Equality: Equals, GetHashCode & IEquatable | Beginner |
| 18 | How does a struct's default Equals() behavior differ from a class's, even without any overrides? C# › Equality: Equals, GetHashCode & IEquatable | C# | Equality: Equals, GetHashCode & IEquatable | Beginner |
| 19 | How do you correctly override Equals() and GetHashCode() together on a class, and why must they always be overridden as a pair? C# › Equality: Equals, GetHashCode & IEquatable | C# | Equality: Equals, GetHashCode & IEquatable | Intermediate |
| 20 | How do you overload comparison operators like < and >, and what consistency rule must they maintain relative to Equals()? C# › Indexers & Operator Overloading | C# | Indexers & Operator Overloading | Intermediate |
| 21 | How should Equals() be implemented differently for a class designed to support INHERITANCE, to correctly handle equality between a base type and derived types? C# › Equality: Equals, GetHashCode & IEquatable | C# | Equality: Equals, GetHashCode & IEquatable | Advanced |
| 22 | How does structural (deep) equality for collections work, and why doesn't List<T>.Equals() perform element-by-element comparison by default? C# › Equality: Equals, GetHashCode & IEquatable | C# | Equality: Equals, GetHashCode & IEquatable | Advanced |
| 23 | What is the recommended way to combine multiple field values into a single hashCode() implementation, following the common formula used by IDE-generated code? Java › equals(), hashCode() & toString() Contracts | Java | equals(), hashCode() & toString() Contracts | Beginner |
| 24 | What is the purpose of overriding toString(), and what's the difference between Object's default implementation and a well-designed custom one? Java › equals(), hashCode() & toString() Contracts | Java | equals(), hashCode() & toString() Contracts | Intermediate |
| 25 | What is the difference between value types and reference types in C#, and how does this affect variable assignment? C# › Value vs Reference Types | C# | Value vs Reference Types | Beginner |
| 26 | What are records in C#, and how do they differ from classes and structs? C# › Records & Pattern Matching | C# | Records & Pattern Matching | Beginner |
| 27 | What are the ordinal() and name() methods on an enum constant, and why is relying on ordinal() for persistence or serialization considered dangerous? Java › Enums | Java | Enums | Intermediate |