I am a beginner for Groovy. I feel confused for the List
interface. According the type, it is an instance of java.util.ArrayList
. And there is no method each
in Java JDK for ArrayList.
Why I can type below code:
list = [1, 2, 3]
list.each { println "- ${it}" }
println list.class
Groovy adds methods to existing classes to support its coding style.
For example these are all the methods added to the List
interface, including the each
method .
A rough overview over the additional features added this way can be found in the Groovy Development Kit overview page .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.