Provides integration with the Scala Programming language
@Scalify simplifies the task of integrating Groovy and Scala code. This transformation adds the required bytecode to your Groovy classes to make them appear as native Scala classes. It also helps when implementing or extending a Scala trait/class from Groovy.
Place @Scalify at the class level, example;
When the trait Output is compiled it will generate bytecode similar to
The first pair of methods is your typical POJO accessors (generated by Scala's @BeanProperty) which Groovy can handle quite well. The second pair of methods represent Scala's native accessors, these will be written by @Scalify (if not present already in your class definition). Additionally @Scalify will make sure that your class implements scala.ScalaObject if it does not already.
One last trick up the sleeve is that @Scalify will generate operator friendly methods, these are the currently supported methods:
Operator |
Groovy |
Scala |
|---|---|---|
+ |
plus() |
$plus() |
- |
minus() |
$minus() |
* |
multiply() |
$times() |
/ |
div() |
$div() |
% |
mod() |
$percent() |
^ |
xor() |
$up() |
& |
and() |
$amp() |
| |
or() |
$bar() |
** |
power() |
$times$times() |
<< |
leftShift() |
$less$less() |
>> |
rightShift() |
$greater$greater() |
- |
negative() |
unary_$minus() |
+ |
positive() |
unary_$plus() |
~ |
bitwiseNegate() |
unary_$tilde() |
| Full compatibility While @Scalify can generate all the require boilerplate code it cannot (at the moment) generate a required class attribute (called pickle) that the Scala compiler uses to gather metadata information about a Scala class. This means you won't be able to call a property setter using the short notation, in other words will result in a compilation error while the following will work |
Make sure to have the Scala compiler & libraries on your classpath. You will also need asm, grab the latest version available with your Groovy distribution