Skip to content

Always override hashCode when you override equals #8

Open
@HelgeStenstrom

Description

See Effective Java by Josua Bloch, item 11.

This will fail in Junit5, and probably in Junit 4 and TestNG too:
assertEquals(new Complex(1, 0), new Complex(1, 0));

because the expected (left) and actual (right) values have different hash codes.

IntelliJ can make a working hashCode method for you in seconds.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions