3 ms·
I agree, but by that same definition, a private reference field in Java that is initialized in the constructor also can't be null. My point is that we can comp
by tsimionescu 3y ago
I agree, but by that same definition, a private reference field in Java that is initialized in the constructor also can't be null.
My point is that we can compare two things: valid programs, or programs that compile.
In valid C++ programs, references can't be null and there are no data races. In valid Java programs, all final fields initialized in an object's constructor have that value for the lifetime of the object.
If we compare invalid programs that compile, which is an important point as well, then those guarantees go out the window. But here Java is much more forgiving than C++: if you have improper synchronization, you may see fields which are null instead of having their final value, which is bad and confusing. But in C++ with improper synchronization, you can see literally any outcome at all.