Nikash
Nikash

Reputation: 38

Do groovy bindings exist for a class?

I've a simple class with a main() method from which I want to access the script bindings.

class Sample {
  public static void main(String[] args) {
    binding.variables.each{ 
      println it.key
      println it.value 
    }
  }
}

Does the implicit binding variable exist for a simple class such as this or is it only for scripts?

I realize I can pass it into the method / the constructor of the object. But since I'd like to keep this as a pure class file and not a script, I cannot do that.

Upvotes: 1

Views: 405

Answers (1)

Jérémie B
Jérémie B

Reputation: 11022

It's only a property of a Script instance. Look at the source, you'll see that a Binding is only a delegate, used in getProperty or setProperty.

Upvotes: 1

Related Questions