我是Groovy的新手(之前在Java上工作),尝试使用Spock框架编写一些测试用例。 我需要将以下Java代码片段使用“each循环”转换为Groovy代码片段。
Java代码片段:
List<String> myList = Arrays.asList("Hello", "World!", "How", "Are", "You");
for( String myObj : myList){
if(myObj==null) {
continue; // need to convert this part in groovy using each loop
}
System.out.println("My Object is "+ myObj);
}
优雅代码示例:
def myObj = ["Hello", "World!", "How", "Are", "You"]
myList.each{ myObj->
if(myObj==null){
//here I need to continue
}
println("My Object is " + myObj)
}