arthurchoonchoi (1) [Avatar] Offline
#1
Hi, I hasve 2 questions:

(q1) Why the println [String, List].'package'.name not working? But, println([String, List].'package'.name) works.

(q2) The spread-dot operator is just for functions, not a property access


Thanks for your help
Mittie (397) [Avatar] Offline
#2
Re: println [String, List].'package'.name
> (q1) Why the println [String, List].'package'.name
> not working? But, println([String,
> List].'package'.name) works.

That's because of operator precedence: (implicit) parentheses are higher than dot, i.e.
println [String, List].'package'.name
would be equivalent to
println([String, List]).'package'.name
and since println returns null, you get an NPE.

> (q2) The spread-dot operator is just for functions,
> not a property access

Spread-dot is for method access and since Groovy 1.5 additionally supported for property access (not mandatory, though)

thanks for posting and keep groovin',
Dierk