我是grails的新手,我在许多例子中发现变量可能以问号结尾(?)
喜欢这个
喜欢这个
boolean equals(other) { if(other?.is(this)) return true }
上面的代码包含If条件,另一个以?结尾?所以我想知道那种表现的意义
解决方法
?。是一个空安全运算符,用于避免意外的NPE。
if ( a?.b ) { .. }
和…一样
if ( a != null && a.b ) { .. }
但在这种情况下,()已经是null安全的,所以你不需要它
other.is( this )
应该是好的。