Re: Confusing AnyRef equals

Georgii Dernovyi <[email protected]> Wed, 14 Dec 2016 08:05:47 -0800 (PST)
Newsgroups gmane.comp.lang.scala
Message-ID <[email protected]>
------=_Part_1263_967996645.1481731547166
Content-Type: multipart/alternative; 
	boundary="----=_Part_1264_1676001336.1481731547167"

------=_Part_1264_1676001336.1481731547167
Content-Type: text/plain; charset=UTF-8



On Wednesday, December 14, 2016 at 11:00:38 PM UTC+7, Georgii Dernovyi 
wrote:
>
> 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_1264_1676001336.1481731547167
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Wednesday, December 14, 2016 at 11:00:38 PM UTC=
+7, Georgii Dernovyi wrote:<blockquote class=3D"gmail_quote" style=3D"margi=
n: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><di=
v 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-fa=
mily:&quot;Courier New&quot;"><span style=3D"color:#000080;font-weight:bold=
">case class </span>a(i:Int)<br>{<br>  <span style=3D"color:#000080;font-we=
ight:bold">override def </span>canEqual(a: Any) =3D a.isInstanceOf[a]<br><b=
r>  <span style=3D"color:#000080;font-weight:bold">override def </span>equa=
ls(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">An=
yRef</span>.hashCode<br>}<br><br><span style=3D"color:#000080;font-weight:b=
old">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"colo=
r:rgb(0,0,0);font-family:&quot;Courier New&quot;"><span style=3D"color:#808=
080;font-style:italic"><br></span></pre><pre style=3D"color:rgb(0,0,0);font=
-family:&quot;Courier New&quot;"><span style=3D"color:#808080;font-style:it=
alic">Am I right? )</span></pre></div></div></div></blockquote></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;scala-language&quot; 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_1264_1676001336.1481731547167--

------=_Part_1263_967996645.1481731547166--