我希望将String
传递给一个函数,该函数允许我在LazyMap
public analyzeLazyMap(String valueToCheck, String keyToAnalyze, ArrayList<LazyMap> arrayOfLazyMaps){
for (LazyMap myLazyMap in arrayOfLazyMaps) {
if (valueToCheck == myLazyMap.$keyToAnalyze) {
return 'bar'
}
}
}
所以在这个电话中我希望myKey进入“Do Something”部分“。假设foobar
将在myArrayListofLazyMaps
String foo = analyzeLazyMap('foobar', 'myKey', myArrayListofLazyMaps,)
println(foo)
//Console Output == bar
答案 0 :(得分:0)
好的,想通了。我的数据不正确
public analyzeLazyMap(String valueToCheck, String keyToAnalyze, ArrayList<LazyMap> arrayOfLazyMaps){
for (LazyMap myLazyMap in arrayOfLazyMaps) {
if (valueToCheck == myLazyMap."$keyToAnalyze") {
return 'bar'
}
}
}
答案 1 :(得分:0)
一点语法糖
arrayOfLazyMaps.each {lazyMap ->
if (lazyMap."$keyToAnalyze" == valueToCheck)
return 'bar'
}