Groovy 中的等效代码

Equivalent code in Groovy

groovy 中是否有与 java 中的以下代码等效的代码:

import java.util.Arrays;
import java.util.List;
import java.util.Random;

class Text {

public static void main(String [] args) {

String [] array = {"hello", "world","Pasci","Jenny"};
List <String> list = Arrays.asList(array);
 {
     Random rand = new Random();
     System.out.println("String from list: " + list.get(rand.nextInt(list.size())));
}
}
}

谢谢

Groovy 的语法更简洁,不像 Java:

那样冗长
def list = ["hello", "world","Pasci","Jenny"]
Random rand = new Random()
println "String from list: " + list.get(rand.nextInt(list.size()))

旁注:Groovy几乎是Java的超集,也就是说,你几乎可以写任何 Java 代码在 groovy 文件中,它将编译并 运行.