252991 (4) [Avatar] Offline
#1
Dear authors,

This is regarding the following sentences in section 3.2.1

- Mutability is represented by any variable or field that is not stable or final...
- Fields should be final so that the compiler can enforce Immutability

I think using the final keyword is language dependent. For example in Java if a field is of type collection then even if it is declared as final, the collection can still be changed.

Maybe this can be reformulated, using language agnostic terminology.


Thanks.
Roland Kuhn (15) [Avatar] Offline
#2
The point of mutable containers is discussed later on, so that should be covered. You are right that that sentence is formulated for a Java context, but it should be clear what is meant—I strongly suspect that C++ developers will translate final to const while reading it. Changing the book it no longer possible at this point, it is already in print.
252991 (4) [Avatar] Offline
#3
Yes, from a C/C++ perspective, absolutely, it would be translated to const. However given the code samples were in Java, thus final doesn't give the same guarantees as in C/C++.

On my end the book is still marked as MEAP so I thought I'd give feedback. But it's good to know that printing has started, looking forward getting the hard copy.

Cheers.