You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by "Pavel_K (Jira)" <ji...@apache.org> on 2020/06/28 07:51:00 UTC
[jira] [Created] (NETBEANS-4512) Add support of inheritance in
generated equals hashcode
Pavel_K created NETBEANS-4512:
---------------------------------
Summary: Add support of inheritance in generated equals hashcode
Key: NETBEANS-4512
URL: https://issues.apache.org/jira/browse/NETBEANS-4512
Project: NetBeans
Issue Type: New Feature
Affects Versions: 12.0
Reporter: Pavel_K
Lets suppose we have two classes - A and B with one field in every class. B extends A. NetBeans generates the following equals and hashCode:
{code:java}
public class A {
private String Foo;
@Override
public int hashCode() {
int hash = 7;
hash = 67 * hash + Objects.hashCode(this.Foo);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final A other = (A) obj;
if (!Objects.equals(this.Foo, other.Foo)) {
return false;
}
return true;
}
}
public class B extends A {
private String bar;
@Override
public int hashCode() {
int hash = 7;
hash = 89 * hash + Objects.hashCode(this.bar);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final B other = (B) obj;
if (!Objects.equals(this.bar, other.bar)) {
return false;
}
return true;
}
}
{code}
As we see A.equals and A.hashCode are not considered in generated B.equals and B.hashCode. The problem was also discussed here: https://stackoverflow.com/a/2067401/5057736 .
So, I suggest to add boolean flag to these two forms like "Inheritance support" and generate equals and hashCode with inheritance support.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists