Ed Clark | 9 May 16:49
Favicon

Re: [groovy-user] dif between def obj = new MyObject() vs MyObject obj = new MyObject()

Jochen Theodorou wrote:
> Peter Niederwieser schrieb:
>> I think the question was about the difference between "def foo =" and
>> "MyObject foo =", not between "def foo =" and "foo =".
>
> my bad...
>
> both declare a local variable (when done in a method or script), only 
> if you use MyObject, then Groovy guarantees you that any value 
> assigned to foo will be at last of class MyObject at runtime. If this 
> rule is violated, then Groovy will throw a runtime exception when the 
> assignment is done. Since the root of all classes is Object using 
> Object won't do anything special. "def" can be seen as alias for 
> Object atm.
>
> bye blackdrag
>
Just curious - are there any performance benefits to specifying the
type, either compile time or run time?  I know that some languages
can speed things up if given some type hints.  (Given the extra
dynamic nature of Groovy, there may be none.)

I do think there are other benefits to explicitly typing, e.g. adding
that little bit of additional info to make the code easier to read and
understand.

Ed Clark

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Gmane