是什么 ?在groovy变量? [英] what is the ? on groovy variables?

查看:102
本文介绍了是什么 ?在groovy变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  trip.id?.encodeAsHTML()

使用或不使用id?的区别是什么?

解决方案

它检查对象是否为null。
使用它,可以防止出现空指针异常。



如果使用它,则应该将它用于整个对象(例如:trip.id ?.otherstuff ?.morestuff?.encodeAsHTML()


I saw in some groovy code this:

trip.id?.encodeAsHTML()

What is the difference between using or not using "id?."?

解决方案

It checks if the object is null or not. Using it, you can prevent nullpointer exception.

If you use it, you should use it for the whole object (eg: trip.id?.otherstuff?.morestuff?.encodeAsHTML()

这篇关于是什么 ?在groovy变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆