Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Groovy: Spread Operator Vs Iterable interface


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

Share the post

Groovy: Spread Operator Vs Iterable interface

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×