@Documented @Incubating @Retention(RetentionPolicy.SOURCE) @Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE}) @GroovyASTTransformationClass("org.codehaus.groovy.transform.OperatorRenameASTTransformation") public @interface OperatorRename
Allows renaming of Groovy's operator methods. This can be useful for using Groovy's operator overloading with libraries designed with different method names. As an example, here is using the Commons Numbers Fraction library. This normally has an "add" method, but we can use the "+" operator using this transform.
@OperatorRename(plus="add") def testAddOfTwoFractions() { var half = Fraction.of(1, 2) var third = Fraction.of(1, 3) assert half + third == Fraction.of(5, 6) }
Type | Name and Description |
---|---|
String |
and
|
String |
compareTo
|
String |
div
|
String |
leftShift
|
String |
minus
|
String |
multiply
|
String |
or
|
String |
plus
|
String |
power
|
String |
remainder
|
String |
rightShift
|
String |
rightShiftUnsigned
|
String |
xor
|