We just have to be a little careful. Rightly or wrongly (search the mailing lists for many discussions), current Groovy's '==' tries to do 'friendly coercion' between types to try to give a business domain friendly meaning to equality:
String[] one = ['a', 'b', 'c'] List<String> two = ['a', 'b', 'c'] assert one.class != two.class assert one == two int[] ints = [1, 2] long[] longs = [1L, 2L] assert ints == longs So as long as we can tell that we have two things that can't possibly be equal, then we should return false. Cheers, Paul. On Thu, Nov 3, 2016 at 11:38 AM, Daniel.Sun <realblue...@hotmail.com> wrote: > I verified the comparing of Java, which will check the type first. e.g. > > new int[2][][].equals(new int[2][]) // false > new int[2].equals(new long[2]) // false > > Cheers, > Daniel.Sun > > > > 在 "bo zhang [via Groovy]" <ml-node+[hidden email] > <http:///user/SendEmail.jtp?type=node&node=5736462&i=0>>,2016年11月3日 > 上午9:24写道: > > Yes, that's my first instinct too, but a few minutes later I found test > cases as follows: > > assert [[[5, 6], [7, 8]]] as int[][][] == [[[5, 6], [7, 8]]] as Long[][][] > > See https://github.com/groovy/groovy-core/blob/master/src/ > test/groovy/ArrayTest.groovy#L207 > > I think this issue can be discussed, anybody has opinions? > > 2016-11-03 7:51 GMT+08:00 Daniel.Sun <[hidden email]>: > >> IMO, we should compare their type first. If not same, the comparing >> result should be 'false'. >> >> Cheers, >> Daniel.Sun >> >> >> >> 在 "bo zhang [via Groovy]" <ml-node+[hidden email]>,2016年11月3日 06:53写道: >> >> I'm afraid it's not a bug. >> >> Actually, `def a=new int[2][]` means that a is an array of two null >> pointers with type "int []", and `def b=new int[2][][]` means that b is an >> array of two null pointers with type "int[][]", it seems that they should >> be equal. >> >> See https://github.com/groovy/groovy-core/blob/master/src/ >> test/groovy/ArrayTest.groovy#L198 >> >> >> >> >> 2016-10-30 18:50 GMT+08:00 Daniel.Sun <[hidden email]>: >> >>> Hi Jochen, >>> >>> I create JIRA issue >>> GROOVY-7983(https://issues.apache.org/jira/browse/GROOVY-7983) to track >>> the >>> issue. >>> >>> BTW, the code in the email should be corrected as follow: >>> >>> def a = new int[2][] >>> def b = new int[2][][] >>> assert a == b // expect faling >>> >>> Cheers, >>> Daniel.Sun >>> >>> >>> >>> -- >>> View this message in context: http://groovy.329449.n5. >>> nabble.com/An-issue-about-comparing-arrays-tp5736379p5736398.html >>> Sent from the Groovy Dev mailing list archive at Nabble.com. >>> >> >> >> >> ------------------------------ >> If you reply to this email, your message will be added to the discussion >> below: >> http://groovy.329449.n5.nabble.com/An-issue-about-comparing-arrays- >> tp5736379p5736458.html >> To unsubscribe from An issue about comparing arrays, click here. >> NAML >> <http://groovy.329449.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> >> >> >> ------------------------------ >> View this message in context: Re: An issue about comparing arrays >> <http://groovy.329449.n5.nabble.com/An-issue-about-comparing-arrays-tp5736379p5736460.html> >> >> Sent from the Groovy Dev mailing list archive >> <http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html> at >> Nabble.com. >> > > > > ------------------------------ > If you reply to this email, your message will be added to the discussion > below: > http://groovy.329449.n5.nabble.com/An-issue-about-comparing-arrays- > tp5736379p5736461.html > To unsubscribe from An issue about comparing arrays, click here. > NAML > <http://groovy.329449.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> > > > ------------------------------ > View this message in context: Re: An issue about comparing arrays > <http://groovy.329449.n5.nabble.com/An-issue-about-comparing-arrays-tp5736379p5736462.html> > Sent from the Groovy Dev mailing list archive > <http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html> at > Nabble.com. >