![]() |
Why String is final in Java?
Hi friends,
I would like to know, Why String is final in Java? |
String is a very core class in Java, many things rely on it working a certain way, for example being immutable. Making the class final prevents subclasses that could break these assumptions. Note that, even now, if you use reflection, you can break Strings (change their value or hashcode).
|
String is a very core class in Java, many things rely on it working a certain way, for example being immutable. Making the class final prevents subclasses that could break these assumptions. Note that, even now, if you use reflection, you can break Strings (change their value or hashcode)
|
String is a very core class in Java, many things rely on it working a certain way, for example being immutable. Making the class final prevents subclasses that could break these assumptions. Note that, even now, if you use reflection, you can break Strings (change their value or hashcode).
|
Once you assign a string object, that object can not be changed in memory. In summary, what you did is to change the reference of "a" to a new string object. Java String is immutable, String will Store the value in the form of object.
|
String is a very core class in Java, many things rely on it working a certain way, for example being immutable. Making the class final prevents subclasses that could break these assumptions. Note that, even now, if you use reflection, you can break Strings (change their value or hashcode).
|
String is a very core class in Java, many things rely on it working a certain way, for example being immutable. Making the class final prevents subclasses that could break these assumptions. Note that, even now, if you use reflection, you can break Strings
|
All times are GMT -7. The time now is 10:34 AM. |
Powered by vBulletin Copyright © 2020 vBulletin Solutions, Inc.