So I stumbled upon the following piece of Java code :
final String osName = System.getProperty("os.name");
I have read in several other StackOverFlow questions that the String class is actually immutable. So I asked myself the following thing, why is it the String declared final?
I am not very good with C++, but in order to understand what happens behind the scenes(in Java) I decided to see what would be the equivalent in C++.
If my understanding is correct making the String final in Java is equivalent in making a pointer in C++ being const, that is what the pointer variable points to cannot be changed. The limitation in Java is that you can change only the constness of the pointer to that String, but the chuck of memory the pointer points to is immutable.
So my question is am I correct or I am missing something else?