A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.pmd-code.org/pmd-doc-7.0.0/pmd_rules_kotlin_errorprone.html below:

Error Prone | PMD Source Code Analyzer

Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors.

Table of Contents OverrideBothEqualsAndHashcode

Since: PMD 7.0.0

Priority: Medium (3)

Override both public boolean Object.equals(Object other), and public int Object.hashCode(), or override neither. Even if you are inheriting a hashCode() from a parent class, consider implementing hashCode and explicitly delegating to your superclass.

This rule is defined by the following Java class: net.sourceforge.pmd.lang.kotlin.rule.errorprone.OverrideBothEqualsAndHashcodeRule

Example(s):

class Bar {        // poor, missing a hashCode() method
    override fun equals(o: Any?): Boolean {
      // do some comparison
    }
}

class Baz {        // poor, missing an equals() method
    override fun hashCode(): Int {
      // return some hash value
    }
}

class Foo {        // perfect, both methods provided
    override fun equals(other: Any?): Boolean {
      // do some comparison
    }
    override fun hashCode(): Int {
      // return some hash value
    }
}

Use this rule by referencing it:

<rule ref="category/kotlin/errorprone.xml/OverrideBothEqualsAndHashcode" />

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4