You can apply Spread (*.) operator on any class that implements the Iterable interface.
HelloWorld.groovy
class Employee{
String firstName
String lastName
}
class CompositeObject implements IterableEmployee> {
def employees = [
new Employee (firstName : "Menon", lastName : "Hari"),
new Employee (firstName : "Bhat", lastName : "Srini"),
new Employee (firstName : "Krishna", lastName : "Gurram")
]
@Override
IteratorEmployee> iterator() {
employees.iterator()
}
}
CompositeObject compositeObj = new CompositeObject()
def firsNames = compositeObj*.firstName
def lastNames = compositeObj*.lastName
println "firstNames : ${firsNames}"
println "lastNames : ${lastNames}"
This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here