Created
April 8, 2014 20:48
-
-
Save Dierk/10189588 to your computer and use it in GitHub Desktop.
Using Groovy traits with @DeleGate AST transform
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
// has all methods of List | |
trait ListLike { | |
@Delegate List linkedList = new LinkedList() | |
} | |
// stores anything but exposes only Strings | |
class StringList implements ListLike { | |
String get(int index) { linkedList.get(index).toString() } | |
} | |
ListLike stringList = new StringList() | |
stringList << 0 // adding an int | |
assert '0' == stringList[0] // getting a String |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See Compatibility with AST transformations it says "Traits are not officially compatible with AST transformations".