Amir Raminfar Amir Raminfar - 1 year ago 120
Groovy Question

What does the question mark mean in GSP/Grails?

I saw this in my generated GSP pages. What does the ? mean?

<g:textField name="name" value="${phoneInstance?.name}" />

Answer Source

It's the "Safe Navigation Operator", which is a Groovy feature that concisely avoids null pointer exceptions. See

In this case, if phoneInstance is null, then it doesn't try to get the name property and cause a NPE - it just sets the value of the field tag to null.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download