Fault tolerance is very complex in the compiler. Yes, you check for null, but there is a problem that your code can be used in a multi-threaded context. Consider this scenario:
This block is executed:
if(testObj == null) {
testObj = new Object();
}
, testObj null. null testObj.
, , :
public Object getTestObj() {
Object tmpObj = testObj
if(tmpObj == null) {
tmpObj = new Object();
testObj = tmpObj;
}
return tmpObj;
}
, .
, , , null.
, , IntelliJ. , nullability . , .