Confusing AnyRef equals
Georgii Dernovyi <[email protected]> Wed, 14 Dec 2016 08:08:39 -0800 (PST)
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_1080_839225836.1481731719571
Content-Type: multipart/alternative;
boundary="----=_Part_1081_238591396.1481731719572"
------=_Part_1081_238591396.1481731719572
Content-Type: text/plain; charset=UTF-8
I found that subj returns false for the same object. It is a terrible
mistake for me
case class a(i:Int)
{
override def canEqual(a: Any) = a.isInstanceOf[a]
override def equals(o:Any) = AnyRef.equals(o)
override def hashCode = AnyRef.hashCode
}
val aa = new a(1)
aa == aa //false
Am I right? )
--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
------=_Part_1081_238591396.1481731719572
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div class=3D"IVILX2C-ed-a" style=3D"padding-left: 5px;"><=
div tabindex=3D"0" class=3D"IVILX2C-nb-P" style=3D"line-height: normal;"><d=
iv style=3D"overflow: auto;"><div style=3D"max-height: 10000px;"><div dir=
=3D"ltr">I found that subj returns false for the same object. It is a terri=
ble mistake for me<div><br><div><pre style=3D"color: rgb(0, 0, 0); font-fam=
ily: "Courier New";"><span style=3D"color: rgb(0, 0, 128); font-w=
eight: bold;">case class </span>a(i:Int)<br>{<br> <span style=3D"color: rg=
b(0, 0, 128); font-weight: bold;">override def </span>canEqual(a: Any) =3D =
a.isInstanceOf[a]<br><br> <span style=3D"color: rgb(0, 0, 128); font-weigh=
t: bold;">override def </span>equals(o:Any) =3D <span style=3D"color: rgb(1=
02, 14, 122); font-style: italic;">AnyRef</span>.equals(o)<br><br> <span s=
tyle=3D"color: rgb(0, 0, 128); font-weight: bold;">override def </span>hash=
Code =3D <span style=3D"color: rgb(102, 14, 122); font-style: italic;">AnyR=
ef</span>.hashCode<br>}<br><br><span style=3D"color: rgb(0, 0, 128); font-w=
eight: bold;">val </span>aa =3D <span style=3D"color: rgb(0, 0, 128); font-=
weight: bold;">new </span>a(<span style=3D"color: rgb(0, 0, 255);">1</span>=
)<br>aa =3D=3D aa <span style=3D"color: rgb(128, 128, 128); font-style: ita=
lic;">//false</span></pre><pre style=3D"color: rgb(0, 0, 0); font-family: &=
quot;Courier New";"><span style=3D"color: rgb(128, 128, 128); font-sty=
le: italic;"><br></span></pre><pre style=3D"color: rgb(0, 0, 0); font-famil=
y: "Courier New";"><span style=3D"color: rgb(128, 128, 128); font=
-style: italic;">Am I right? )</span></pre></div></div></div></div></div></=
div><div></div><div></div></div><div><div class=3D"IVILX2C-ed-a" style=3D"m=
argin-left: 44px; padding-left: 5px;"></div></div><div class=3D"IVILX2C-nb-=
b" style=3D"padding-left: 5px;"><div class=3D"IVILX2C-nb-a IVILX2C-nb-cb" s=
tyle=3D"padding-top: 4px; padding-bottom: 4px; position: relative;"><div st=
yle=3D"display: inline-block;"></div><div class=3D"IVILX2C-md-a" style=3D"m=
argin-top: 4px; position: relative; height: 34px;"></div></div></div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;scala-language" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">scal=
[email protected]</a>.<br />
For more options, visit <a href=3D"https://groups.google.com/d/optout">http=
s://groups.google.com/d/optout</a>.<br />
------=_Part_1081_238591396.1481731719572--
------=_Part_1080_839225836.1481731719571--