Re: Re: Confusing AnyRef equals

Vlad Patryshev <[email protected]> Wed, 14 Dec 2016 08:10:51 -0800
Newsgroups gmane.comp.lang.scala
Message-ID <CAFhNTo-nRsCiNtWHTTFMY0t9fA_SsJvTP2zRM7XbjhRYGs65Gw@mail.gmail.com>
--001a11447a44dcc95b0543a0950a
Content-Type: text/plain; charset=UTF-8

This is beautiful.

val AnyRef = new Specializable {
  override def toString = "object AnyRef"
}


Thanks,
-Vlad

On Wed, Dec 14, 2016 at 8:05 AM, Georgii Dernovyi <[email protected]>
wrote:

>
>
> 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.
>

-- 
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.

--001a11447a44dcc95b0543a0950a
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">This is beautiful.<div><br></div><div><pre style=3D"backgr=
ound-color:rgb(253,246,227);color:rgb(88,110,117);font-family:&quot;input m=
ono&quot;;font-size:9pt"><span style=3D"color:rgb(0,0,128);font-weight:bold=
">val </span><span style=3D"color:rgb(63,0,128)">AnyRef </span>=3D <span st=
yle=3D"color:rgb(0,0,128);font-weight:bold">new </span>Specializable {<br> =
 <span style=3D"color:rgb(0,0,128);font-weight:bold">override def </span>to=
String =3D <span style=3D"color:rgb(0,128,0);font-weight:bold">&quot;object=
 AnyRef&quot;<br></span>}<br></pre></div></div><div class=3D"gmail_extra"><=
br clear=3D"all"><div><div class=3D"gmail_signature" data-smartmail=3D"gmai=
l_signature">Thanks,<br>-Vlad</div></div>
<br><div class=3D"gmail_quote">On Wed, Dec 14, 2016 at 8:05 AM, Georgii Der=
novyi <span dir=3D"ltr">&lt;<a href=3D"mailto:[email protected]" target=
=3D"_blank">[email protected]</a>&gt;</span> wrote:<br><blockquote class=
=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=
ing-left:1ex"><div dir=3D"ltr"><span class=3D""><br><br>On Wednesday, Decem=
ber 14, 2016 at 11:00:38 PM UTC+7, Georgii Dernovyi wrote:</span><blockquot=
e class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px=
 #ccc solid;padding-left:1ex"><div dir=3D"ltr"><span class=3D"">I found tha=
t subj returns false for the same object. It is a terrible mistake for me</=
span><div><br><div><pre style=3D"color:rgb(0,0,0);font-family:&quot;Courier=
 New&quot;"><span style=3D"color:#000080;font-weight:bold">case class </spa=
n>a(i:Int)<br>{<br>  <span style=3D"color:#000080;font-weight:bold">overrid=
e def </span>canEqual(a: Any) =3D a.isInstanceOf[a]<span class=3D""><br><br=
>  <span style=3D"color:#000080;font-weight:bold">override def </span>equal=
s(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">Any=
Ref</span>.hashCode<br>}<br><br><span style=3D"color:#000080;font-weight:bo=
ld">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></span></pre><pre style=
=3D"color:rgb(0,0,0);font-family:&quot;Courier New&quot;"><span style=3D"co=
lor:#808080;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:italic">Am I right? )</span></pre></div></div></div></blockquote></di=
v><div class=3D"HOEnZb"><div class=3D"h5">

<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]" targ=
et=3D"_blank">scala-language+unsubscribe@<wbr>googlegroups.com</a>.<br>
For more options, visit <a href=3D"https://groups.google.com/d/optout" targ=
et=3D"_blank">https://groups.google.com/d/<wbr>optout</a>.<br>
</div></div></blockquote></div><br></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 />

--001a11447a44dcc95b0543a0950a--