I thought that implicit variables would overcome this.  Not an elegant solution 
- as you are simply declaring variables on the fly without an explicit data 
type or even a 'def'.
Having said, it is generally safer to explicitly list the parameters used in a 
method when used in this context (e.g. in a script without an explicit class 
declaration to mop up this case).
And as for 'global' - I sure wish the word 'global' was used instead of 
'static'.  It just kinda makes more sense to me!
//===========
   test=''  //implicit declaration of a variable
   void func()
   {
      println(test)
   }
   test = 'hello'
   func()
//===========

Or just

//===========
   void func()
   {
      println(test)
   }
   test = 'hello'
   func()  
//===========

Merlin Beedell 
-----Original Message-----
From: MG <mg...@arscreat.com> 
Sent: 15 October 2020 6:21 PM
To: users@groovy.apache.org; Jochen Theodorou <blackd...@gmx.org>
Subject: Re: Defining a global variable

On 15/10/2020 18:27, Jochen Theodorou wrote:
> well.. even scripts are first compiled into a class before the class 
> is then executed. Groovy has no interpreter

Which, I think, is a lesser known fact, and quite surprising to people who 
perceive Groovy just under its "script language" aspect ;-)


Reply via email to