I am trying to redefine dynamic methods of a domain in groovy. Is there something similar alias method in ruby in groovy?
In Groovy, we can add a method named call to a class and then invoke the method without using the name call . We would simply just type the parentheses and optional arguments on an object instance. Groovy calls this the call operator: () . This can be especially useful in for example a DSL written with Groovy.
A method is in Groovy is defined with a return type or with the def keyword. Methods can receive any number of arguments. It's not necessary that the types are explicitly defined when defining the arguments. Modifiers such as public, private and protected can be added.
2. Meaning of the def Keyword. The def keyword is used to define an untyped variable or a function in Groovy, as it is an optionally-typed language.
In Java, Alias is used when reference, which is of more than one, is linked to the same object. The issue with aliasing is when a user writes to a particular object, and the owner for the several other references do not expect that object to change.
Do you mean like the method reference operator .&
?
def out = System.out.&println
out << "Hello"
and
def greet(name) {
println "Hello $name"
}
def sayHello = this.&greet
sayHello "Ronny"
It is mentioned at http://groovy.codehaus.org/Operators but an example is missing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With