This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 206775 - hashCode generation on JDK 7 should use java.util.Objects.hash(...)
Summary: hashCode generation on JDK 7 should use java.util.Objects.hash(...)
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Editor (show other bugs)
Version: 7.2
Hardware: All All
: P3 normal with 2 votes (vote)
Assignee: Dusan Balek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-28 18:54 UTC by Jesse Glick
Modified: 2014-12-09 00:07 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2011-12-28 18:54:46 UTC
Given

    private int x;
    private URL stuff;
    private String whatever;

rather than generating

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 17 * hash + this.x;
        hash = 17 * hash + Objects.hashCode(this.stuff);
        hash = 17 * hash + Objects.hashCode(this.whatever);
        return hash;
    }

I would expect the simpler and more readable

    @Override
    public int hashCode() {
        return Objects.hash(x, stuff, whatever);
    }
Comment 1 iluvtr 2014-12-09 00:07:13 UTC
This improvement benefits code clarity and takes advantage of features introduced since Java 7