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 124163 - Have "Generate hashCode()" generate positive instead of negative tests
Summary: Have "Generate hashCode()" generate positive instead of negative tests
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Editor (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P3 blocker (vote)
Assignee: Dusan Balek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-12-17 21:09 UTC by matthies
Modified: 2013-09-02 14:23 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 matthies 2007-12-17 21:09:28 UTC
"Generate hashCode()" generates code like:

    this.field != null ? this.field.hashCode() : 0

It is generally preferable to express logical conditions without negation when there is the choice. (There are 
situations where there is no choice, such as an 'if' on a negative condition whith no 'else' branch. But this is not 
the case here.) I'd like to suggest to generate

    this.field == null ? 0 : this.field.hashCode()

instead. Besides getting rid of the (double) negation ("is not not an object"), it also places the simple case ("0") 
first, which minimizes the mental stack when reading such code.