Skip to content

Instantly share code, notes, and snippets.

@namuan
Created August 27, 2013 10:30
Show Gist options
  • Save namuan/6351951 to your computer and use it in GitHub Desktop.
Save namuan/6351951 to your computer and use it in GitHub Desktop.
Mixins and Category in groovy
class Foo {
def fooMethod(String message) {
println "fooMethod: ${message}"
}
}
class Bar {
def barMethod(String message) {
println "barMethod: ${message}"
}
}
@Category(Integer)
class IntegerAbility {
def triple() {
this * 3
}
}
Bar.mixin Foo
new Bar().fooMethod("Hello foo from Bar")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment