I have the following:
if (params.query?.equals(g.message(code: "layouts.main.search"))) {
params.query = ""
}
What does the '?' part do?
I have the following:
if (params.query?.equals(g.message(code: "layouts.main.search"))) {
params.query = ""
}
What does the '?' part do?
It is a safeNavigation operator which returns nulls instead of throwing NullPointerExceptions.
Check the operators available in Groovy
http://docs.groovy-lang.org/latest/html/documentation/index.html#_safe_navigation_operator
from groovy.org
Safe Navigation Operator (?.) The Safe Navigation operator is used to avoid a NullPointerException. Typically when you have a reference to an object you might need to verify that it is not null before accessing methods or properties of the object. To avoid this, the safe navigation operator will simply return null instead of throwing an exception, like so:
def user = User.find( "admin" ) //this might be null if 'admin' does not exist
def streetName = user?.address?.street //streetName will be null if user or user.address is null - no NPE thrown
here the explantion for the ? operator:
http://groovy.codehaus.org/Operators#Operators-SafeNavigationOperator
in your case the ? operator protects the method call "equals" on a null object, e.g. the query param cannot be found in the parameter list.