Skip to content

Instantly share code, notes, and snippets.

@jonatasemidio
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonatasemidio/52ee4d8873949448069a to your computer and use it in GitHub Desktop.
Save jonatasemidio/52ee4d8873949448069a to your computer and use it in GitHub Desktop.
Listando classes diferentes com metodos iguais
Object.metaClass.findAll{println it.toString()}
class Dog{ String name; public String toString(){ return this.name } }
class Cat{ String name; public String toString(){ return this.name } }
class Cow{ String name; public String toString(){ return this.name } }
dog = new Dog(name: 'toto')
​cat = new Dog(name: 'lili')
cow = new Dog(name: 'mumu')
[dog, cat, cow].each { it.findAll() }
[dog, cat, cow]*.findAll().sum()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment