What does the question mark mean in GSP/Grails?

前端 未结 4 506
没有蜡笔的小新
没有蜡笔的小新 2021-01-31 14:58

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


4条回答
  •  野性不改
    2021-01-31 15:38

    It's the "Safe Navigation Operator", which is a Groovy feature that concisely avoids null pointer exceptions. See http://docs.groovy-lang.org/latest/html/documentation/index.html#_safe_navigation_operator

    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.

提交回复
热议问题