[prev in list] [next in list] [prev in thread] [next in thread] 

List:       groovy-user
Subject:    Re: [groovy-user] Can not really override equals with category class from java.lang.Number to a self
From:       Jim White <james.paul.white () gmail ! com>
Date:       2014-09-30 8:21:41
Message-ID: CAMpkrpQ1zZzgSfqW9SMjiLaDuw8EXiSVmBzMQ00QRfOzdPaRyA () mail ! gmail ! com
[Download RAW message or body]

That indeed looks like a problem and I find the issue on SO:

http://stackoverflow.com/questions/24963680/groovy-override-compareto

The relevant (and very old) JIRA is:

https://jira.codehaus.org/browse/GROOVY-1765
http://jira.codehaus.org/browse/GROOVY-1888

Those point out some very bad behavior in that:

use(MyCategory) {
    println(ec == 5)
    println(5 == ec)
    println(5.equals(ec))
}
==>
true
false
true



On Tue, Sep 30, 2014 at 12:45 AM, vetko <attila.vetesi@gmail.com> wrote:

> We have difficulties overriding 'equals' with a self-defined Category class
> in case we want to introduce a new DSL that can test equality between
> self-defined classes and numbers/strings. It works in one direction, but it
> doesn't work when the accepting class ('this' class) is a specific(?) Java
> class, like Number (Integer, BigDecimal) or String. Although it does work
> for example on ArrayList in both directions.
> 
> Is there any explication behind this, and does thid work as designed?
> Because we have a very important task depending on this and would be really
> critical for us to work.
> 
> We are currently using Groovy 2.3.6 (non-indy).
> Here is an example evaluable in any Groovy Console:
> 
> class EmptyClass {
> }
> 
> class MyCategory {
> static boolean equals(EmptyClass ec, Number n) {
> return true;
> }
> static boolean equals(Number n, EmptyClass ec) {
> return true;
> }
> }
> 
> def ec = new EmptyClass()
> 
> use(MyCategory) {
> println(ec == 5)
> println(5 == ec)
> }
> 
> > > the output is:
> true
> false
> > > > 
> 
> Thank You for your help.
> Best regards,
> vetko.
> 
> 
> 
> --
> View this message in context:
> http://groovy.329449.n5.nabble.com/Can-not-really-override-equals-with-category-class-from-java-lang-Number-to-a-self-defined-one-tp5721370.html
>  Sent from the groovy - user mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
> 
> http://xircles.codehaus.org/manage_email
> 
> 
> 


[Attachment #3 (text/html)]

<div dir="ltr">That indeed looks like a problem and I find the issue on \
SO:<div><br></div><div><a \
href="http://stackoverflow.com/questions/24963680/groovy-override-compareto">http://st \
ackoverflow.com/questions/24963680/groovy-override-compareto</a><br></div><div><br></div><div>The \
relevant (and very old) JIRA is:</div><div><br></div><div><a \
href="https://jira.codehaus.org/browse/GROOVY-1765">https://jira.codehaus.org/browse/GROOVY-1765</a><br></div><div><a \
href="http://jira.codehaus.org/browse/GROOVY-1888">http://jira.codehaus.org/browse/GROOVY-1888</a><br></div><div><br></div><div>Those \
point out some very bad behavior in that:<br></div><div><br></div><blockquote \
style="margin:0 0 0 40px;border:none;padding:0px"><div><div><font face="comic sans \
ms, sans-serif">use(MyCategory) {</font></div></div><div><div><font face="comic sans \
ms, sans-serif">      println(ec == 5)</font></div></div><div><div><font face="comic \
sans ms, sans-serif">      println(5 == ec)</font></div></div><div><div><font \
face="comic sans ms, sans-serif">      \
println(5.equals(ec))</font></div></div><div><font face="comic sans ms, \
sans-serif">}</font></div><div><font face="comic sans ms, \
sans-serif">==&gt;</font></div><div><font face="comic sans ms, \
sans-serif">true</font></div><div><font face="comic sans ms, \
sans-serif">false</font></div><div><font face="comic sans ms, \
sans-serif">true</font></div></blockquote><div><br></div></div><div \
class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 30, 2014 at 12:45 AM, \
vetko <span dir="ltr">&lt;<a href="mailto:attila.vetesi@gmail.com" \
target="_blank">attila.vetesi@gmail.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">We have difficulties overriding &#39;equals&#39; with a \
self-defined Category class<br> in case we want to introduce a new DSL that can test \
equality between<br> self-defined classes and numbers/strings. It works in one \
direction, but it<br> doesn&#39;t work when the accepting class (&#39;this&#39; \
class) is a specific(?) Java<br> class, like Number (Integer, BigDecimal) or String. \
Although it does work<br> for example on ArrayList in both directions.<br>
<br>
Is there any explication behind this, and does thid work as designed?<br>
Because we have a very important task depending on this and would be really<br>
critical for us to work.<br>
<br>
We are currently using Groovy 2.3.6 (non-indy).<br>
Here is an example evaluable in any Groovy Console:<br>
<br>
class EmptyClass {<br>
}<br>
<br>
class MyCategory {<br>
      static boolean equals(EmptyClass ec, Number n) {<br>
            return true;<br>
      }<br>
      static boolean equals(Number n, EmptyClass ec) {<br>
            return true;<br>
      }<br>
}<br>
<br>
def ec = new EmptyClass()<br>
<br>
use(MyCategory) {<br>
      println(ec == 5)<br>
      println(5 == ec)<br>
}<br>
<br>
&gt;&gt; the output is:<br>
true<br>
false<br>
&gt;&gt;&gt;<br>
<br>
Thank You for your help.<br>
Best regards,<br>
vetko.<br>
<br>
<br>
<br>
--<br>
View this message in context: <a \
href="http://groovy.329449.n5.nabble.com/Can-not-really-override-equals-with-category-class-from-java-lang-Number-to-a-self-defined-one-tp5721370.html" \
target="_blank">http://groovy.329449.n5.nabble.com/Can-not-really-override-equals-with \
-category-class-from-java-lang-Number-to-a-self-defined-one-tp5721370.html</a><br> \
Sent from the groovy - user mailing list archive at Nabble.com.<br> <br>
---------------------------------------------------------------------<br>
To unsubscribe from this list, please visit:<br>
<br>
      <a href="http://xircles.codehaus.org/manage_email" \
target="_blank">http://xircles.codehaus.org/manage_email</a><br> <br>
<br>
</blockquote></div><br></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic