Groovy有一个很好的安全解除引用运算符,这有助于避免NullPointerExceptions:
variable?.method()
method只有在variable没有的情况下才会被调用null.
method
variable
null
有没有办法在Python中做同样的事情?或者我必须写if variable: variable.method()?
if variable: variable.method()
python null groovy nullpointerexception
groovy ×1
null ×1
nullpointerexception ×1
python ×1