How do I create and access the global variables in Groovy?
问题 I need to store a value in a variable in one method and then I need to use that value from that variable in another method or closure. How can I share this value? 回答1: In a Groovy script the scoping can be different than expected. That is because a Groovy script in itself is a class with a method that will run the code, but that is all done runtime. We can define a variable to be scoped to the script by either omitting the type definition or in Groovy 1.8 we can add the @Field annotation.