×

Loading...

我公司的解决方案。

sxffff (lookingforjob)
Consider this code:
var aList = getAListOfStrings()
if(aList.get(0).isEmpty()) {
print("The first string is empty")
}
This code can cause a NullPointerException if either the list or the first string in the list is null. We can address this by using the null-safe invocation operator ?.:

var aList = getAListOfStrings()
if(aList?.get(0)?.isEmpty()) {
print("The first string is empty")
}
The null safe invocation operator works on both methods and properties.
(#9849521@0)
2015-12-24 -05:00
Reply
Page address has been copied.
To share, click to copy page address.
Share Online by QR Code

Back To Topic: 节前最后一刻,写点我对Null的思考。

Back To Forum: HOME枫下论坛枫下论坛主坛工作学习学科技术