我是 Groovy 的初学者。我对 List
界面感到困惑。根据类型,它是java.util.ArrayList
的一个实例。 Java JDK 中没有针对 ArrayList 的方法 each
。
为什么我可以输入以下代码:
list = [1, 2, 3]
list.each { println "- ${it}" }
println list.class
最佳答案
Groovy 向现有类添加方法以支持其编码风格。
例如these are all the methods added to the List
接口(interface),包括the each
method .
以这种方式添加的附加功能的粗略概述可以在 Groovy Development Kit overview page 中找到。 .
关于java - 为什么我可以在 Groovy 的 List 接口(interface)中使用方法 'each'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57354500/