Groovy 使用contains从列表中查找字符串未按预期工作

Groovy 使用contains从列表中查找字符串未按预期工作,groovy,Groovy,我有一份清单,定义如下: def list1=["Test1","Test2","Test3"] String str="Test2" println("Found The String is:"+list1.contains(str)); //It is returning false even though there is a matching string. 你在那里输入的内容确实有效,所以还有其他问题。我猜你做过这样的事情: String part = "Test" String

我有一份清单,定义如下:

def list1=["Test1","Test2","Test3"]
String str="Test2"

println("Found The String is:"+list1.contains(str));

//It is returning false even though there is a matching string.

你在那里输入的内容确实有效,所以还有其他问题。我猜你做过这样的事情:

String part = "Test"
String str="Test2"
def list1=["${part}1","${part}2","Test3"]
def found = list1.contains(str)
在这种情况下,
found
将为false。。。因为:

“${'test'}”
不等于
“test”
,对于相等的某些定义。。。即使打印它们都会让你这么想


原因如下:

这个示例对我来说并没有失败(Groovy 2.5.6)对我来说也适用(Groovy 2.4.8,JVM 1.8.0201[不确定JVM是否与之相关])