So, I came across the following piece of Java code:
final String osName = System.getProperty("os.name");
I read on several other StackOverFlow questions that the String class is actually immutable. So I asked myself the following: why is the string declared final?
I am not very good at C ++, but in order to understand what is going on behind the scenes (in Java), I decided to see what would be equivalent in C ++.
If my understanding is correct, then ending a line in Java is equivalent to having a pointer in C ++ as a constant, then what the pointer of a pointer indicates cannot be changed. The limitation in Java is that you can only change the pointer constant to this string, but the memory patch pointed to by the pointer is unchanged.
So my question is: am I right, or am I missing something else?
source
share