I am not sure that this operator is not deprecated, however Grails uses such syntaxis during the generation of views. As far as I know it is possible to use an operator "?" in two ways - at first, as "save navigation operator", and also in cycles at the end of collection - for(v in list?). Sense of this operator was that will not be Nullpointerexception if collection is null. Such conduct is not needed now, because for..in will not give Nullpointerexception even without using of this operator.... But anyway this construction meets (it can be in old source codes), for example during the generation of views Grais of version 0.6 I see such construction - <g:each var='p' in='${application?.params?}'> ... </g:each>
possibly I'm wrong concerning the use of operator in the construction for..in .... possibly such construction is used only in GSP. For example here is the text from a book "The Definitive Guide to Grails", page 224 -
________________________________________________________ On line 24 you iterate over each suggestion. Note the use of the safe-dereference operator, ?:
<g:each in="${suggestions?}">
By appending the question mark at the end of the variable name inside the expression, you safeguard against any null pointer exceptions being thrown. ________________________________________________________
What is that 'list?' ? I don't know that syntax construct.
Eugene.
Cancelled.
Message was edited by:
Randall Schulz
I am not sure that this operator is not deprecated, however Grails uses such syntaxis during the generation of views. As far as I know it is possible to use an operator "?" in two ways - at first, as "save navigation operator", and also in cycles at the end of collection - for(v in list?). Sense of this operator was that will not be Nullpointerexception if collection is null. Such conduct is not needed now, because for..in will not give Nullpointerexception even without using of this operator.... But anyway this construction meets (it can be in old source codes), for example during the generation of views Grais of version 0.6 I see such construction -
<g:each var='p' in='${application?.params?}'>
...
</g:each>
possibly I'm wrong concerning the use of operator in the construction for..in .... possibly such construction is used only in GSP. For example here is the text from a book "The Definitive Guide to Grails", page 224 -
________________________________________________________
On line 24 you iterate over each suggestion. Note the use of the safe-dereference operator, ?:
<g:each in="${suggestions?}">
By appending the question mark at the end of the variable name inside the expression, you
safeguard against any null pointer exceptions being thrown.
________________________________________________________
Eugene, as you can see in Groovy antlr file placed here:
http://svn.groovy.codehaus.org/browse/groovy/trunk/groovy/groovy-core/src/main/org/codehaus/groovy/antlr/groovy.g
there is no usages for "?" operator but wildcard type parameter.
Your treatment of its semantics as "safe reference" in cycle is clear, but I didn't meet it in any Groovy code.