You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Shil Sinha (JIRA)" <ji...@apache.org> on 2015/07/23 17:37:05 UTC
[jira] [Commented] (GROOVY-7450) List contains String and GString
[ https://issues.apache.org/jira/browse/GROOVY-7450?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14639012#comment-14639012 ]
Shil Sinha commented on GROOVY-7450:
------------------------------------
This is a consequence of {{contains}} using the searched for object's {{equals}} method (in your case, the equals method defined in groovy.lang.GString) to determine membership. The equality check in the closure you passed to {{find}} uses {{ScriptBytecodeAdapter.compareEquals}}, which converts GStrings to Strings before comparing the two.
> List contains String and GString
> --------------------------------
>
> Key: GROOVY-7450
> URL: https://issues.apache.org/jira/browse/GROOVY-7450
> Project: Groovy
> Issue Type: Bug
> Reporter: Mathias Fonseca
>
> I have a List of Strings (Java Strings, not GStrings). On the other hand, I have two String variables. I concat those variables in a new one and get a GString instance.
> The problem is that if I then try to find an element in the list by using contains and passing the GString variable to find, it returns false.
> My workaround for now is to use find instead of contains, but shouldn't it be corrected?
> {code:java}
> def list = ['word1 word2','word3 word4']
> def w1 = 'word1'
> def w2 = 'word2'
> def word = "$w1 $w2"
> assert list.contains(word) //should return true
> assert list.find { it == word } //returns true
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)