9 May 16:49
Re: [groovy-user] dif between def obj = new MyObject() vs MyObject obj = new MyObject()
From: Ed Clark <eaclark@...>
Subject: Re: [groovy-user] dif between def obj = new MyObject() vs MyObject obj = new MyObject()
Newsgroups: gmane.comp.lang.groovy.user
Date: 2008-05-09 14:49:13 GMT
Subject: Re: [groovy-user] dif between def obj = new MyObject() vs MyObject obj = new MyObject()
Newsgroups: gmane.comp.lang.groovy.user
Date: 2008-05-09 14:49:13 GMT
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
RSS Feed