Reputation: 1263
I was wondering if it's posible to get the declared name of a variable within a method? So I can print it out or do something with the name later on. Hopefully the below code example gives more meaning.
Code example:
class Foo {
public method(String param) {
println param.(the method I don't know) +": "+ param
}
}
Foo foo = new Foo()
String myStringVar = "This is a string for testing"
foo.method(myStringVar) //Should print out: "myStringVar: This is a string for testing"
Upvotes: 1
Views: 341
Reputation: 11062
AFAIK this is not possible out of the box. But you can use named arguments:
http://docs.groovy-lang.org/latest/html/documentation/#_named_arguments
Upvotes: 3