4
下面的Groovy代碼塊打印一個空列表:Groovy的「中」經營者與字符串和GString的元素列表
List<String> list = ["test-${1+2}", "test-${2+3}", "test-${3+4}"]
List<String> subl = ["test-1", "test-2", "test-3"]
println subl.findAll { it in list }
輸出:
[]
然而,這種修改會導致正確的輸出:
List<String> list = ["test-${1+2}" as String, "test-${2+3}" as String, "test-${3+4}" as String]
List<String> subl = ["test-1", "test-2", "test-3"]
println subl.findAll { it in list }
輸出:
[test-3]
但是這個「解決方案」感覺非常笨重。
什麼是正確的Groovy方式來實現這一目標?
正是我需要的,非常感謝。 – Matthias 2014-10-29 15:27:09