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 163561

Summary: options to equals-hashcode generator
Product: java Reporter: aekold <aekold>
Component: EditorAssignee: Dusan Balek <dbalek>
Status: RESOLVED DUPLICATE    
Severity: blocker    
Priority: P3    
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:

Description aekold 2009-04-24 10:31:21 UTC
Have suggestions to improve equals code:
1. add block to the start of method:
        if (this == obj) {
            return true;
        }
2. add checkbox to allow check by instance but not class:
        if (!(obj instanceof <currenttype>)) {
            return false;
        }
this option will be useful for some JPA implementations whos getClass is not the same as current.
Comment 1 aekold 2009-04-24 10:34:24 UTC
Here is some code from my EqualsHashCodeGenerator.java:
        // if (obj == this) return true;
        statements.add(make.If(make.Binary(Tree.Kind.EQUAL_TO, make.Identifier("this"), make.Identifier("obj")), 
make.Return(make.Identifier("true")), null));


        //if (!(obj instanceof <this type>)) return false;
        statements.add(make.If(make.Unary(Tree.Kind.LOGICAL_COMPLEMENT, 
make.Parenthesized(make.InstanceOf(make.Identifier("obj"), make.Type(type)))), make.Return(make.Identifier("false")), 
null));
Comment 2 markiewb 2013-08-10 13:20:55 UTC

*** This bug has been marked as a duplicate of bug 156994 ***