> On 13 Feb 2020, at 16:00, Jonathan Gibbons <jonathan.gibb...@oracle.com> > wrote: > > On 2/13/20 7:50 AM, Pavel Rappo wrote: >> a. jdk/javadoc/internal/doclets/formats/html/AbstractTreeWriter.java:143 >> >> Shouldn't it use equals() instead of `==` in this case? A quick look shows a >> surprising number of reference equality checks on >> javax.lang.model.element.Name >> and javax.lang.model.element.Element instances. Why would we need to use >> reference equality on types with explicitly defined equals() and hashCode()? > > == is correct for Name and Symbol/Element
Thanks for the clarification. Out of curiosity, why is that? I can see that equals() is currently implemented through reference equality in concrete subtypes of Symbol & Element: public boolean equals(Object obj) { return (this == obj); } Still, those types explicitly define equals(). One would think using it is a must. Given the current implementation (there's only one that I can see) of Name it's even more surprising: /** Is this name equal to other? */ @DefinedBy(Api.LANGUAGE_MODEL) public boolean equals(Object other) { if (other instanceof Name) return table == ((Name)other).table && index == ((Name) other).getIndex(); else return false; }