Confusing AnyRef equals
Georgii Dernovyi <[email protected]> Wed, 14 Dec 2016 08:00:38 -0800 (PST)
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_5646_932709533.1481731238209
Content-Type: multipart/alternative;
boundary="----=_Part_5647_1735040888.1481731238210"
------=_Part_5647_1735040888.1481731238210
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[Int]
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_5647_1735040888.1481731238210
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">I found that subj returns false for the same object. It is=
a terrible mistake for me<div><br><div><pre style=3D"color: rgb(0, 0, 0); =
font-family: "Courier New";"><span style=3D"color:#000080;font-we=
ight:bold;">case class </span>a(i:Int)<br>{<br> <span style=3D"color:#0000=
80;font-weight:bold;">override def </span>canEqual(a: Any) =3D a.isInstance=
Of[Int]<br><br> <span style=3D"color:#000080;font-weight:bold;">override d=
ef </span>equals(o:Any) =3D <span style=3D"color:#660e7a;font-style:italic;=
">AnyRef</span>.equals(o)<br><br> <span style=3D"color:#000080;font-weight=
:bold;">override def </span>hashCode =3D <span style=3D"color:#660e7a;font-=
style:italic;">AnyRef</span>.hashCode<br>}<br><br><span style=3D"color:#000=
080;font-weight:bold;">val </span>aa =3D <span style=3D"color:#000080;font-=
weight:bold;">new </span>a(<span style=3D"color:#0000ff;">1</span>)<br>aa =
=3D=3D aa <span style=3D"color:#808080;font-style:italic;">//false</span></=
pre><pre style=3D"color: rgb(0, 0, 0); font-family: "Courier New"=
;"><span style=3D"color:#808080;font-style:italic;"><br></span></pre><pre s=
tyle=3D"color: rgb(0, 0, 0); font-family: "Courier New";"><span s=
tyle=3D"color:#808080;font-style:italic;">Am I right? )</span></pre></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_5647_1735040888.1481731238210--
------=_Part_5646_932709533.1481731238209--