Created
August 27, 2013 10:30
-
-
Save namuan/6351951 to your computer and use it in GitHub Desktop.
Mixins and Category in groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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