Skip to content

Latest commit

 

History

History
27 lines (18 loc) · 612 Bytes

EqualsAlwaysReturnsTrueOrFalse.md

File metadata and controls

27 lines (18 loc) · 612 Bytes

Pattern: Constant return value for equals()

Issue: -

Description

Reports equals() methods which will always return true or false. Equals methods should always report if some other object is equal to the current object.

Example of incorrect code:

override fun equals(other: Any?): Boolean {
    return true
}

Example of correct code:

override fun equals(other: Any?): Boolean {
    return this == other
}

Further Reading