Java Mailing List Archive

http://www.gg3721.com/

Home » user.groovy »

Re: [groovy-user] Safe dereference for nested maps

Jochen Theodorou

2008-08-24

Replies: Find Java Web Hosting

Author LoginPost Reply
pexatus schrieb:
> I have a map of maps, so that it can be used like a generalization of a 2D
> array; i.e.
>
> def map = ['a':['b':'c'], 'd':['e':'f']]
>
> I want to use the safe dereference operator, but it does not work with the
> subscript operator. In other words, I want to do this;
>
> if (map['a']?['b'] != null) {
>  // process map['a']['b']
> }
>
> But this does not work. Instead, I do this:
>
> if (map.getAt('a')?.getAt('b') != null) {
>  // process map['a']['b']
> }

how about:

map.a?.b

bye blackdrag

--
Jochen "blackdrag" Theodorou
The Groovy Project Tech Lead (http://groovy.codehaus.org)
http://blackdragsview.blogspot.com/
http://www.g2one.com/

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

  http://xircles.codehaus.org/manage_email


©2008 gg3721.com - Jax Systems, LLC, U.S.A.