+ 4

Why is string final in Java?

25th Sep 2019, 5:43 PM
Isaiah Egbokhan
Isaiah Egbokhan - avatar
8 odpowiedzi
+ 4
Yea i think i got the answer The string is Immutable in Java because String objects are cached in String pool. Since cached String literals are shared between multiple clients there is always a risk, where one client's action would affect all another client. For example, if one client changes the value of String "Test" to "TEST", all other clients will also see that value as explained in the first example. Since caching of String objects was important from performance reason this risk was avoided by making String class Immutable. At the same time, String was made final so that no one can compromise invariant of String class by extending and overriding behaviours.
26th Sep 2019, 6:25 AM
Isaiah Egbokhan
Isaiah Egbokhan - avatar
+ 1
Search about jvm memory and string pool and you will understand why string is imutable object . the objectif is to reduce memory space
26th Sep 2019, 4:17 PM
Mohammed Gamgami
Mohammed Gamgami - avatar
+ 1
Talha altinel there's no multiple inheritance because you will have problem it's called Diamond noir you can search about it if you need help send me message and i will explain what's diamond
26th Sep 2019, 4:59 PM
Mohammed Gamgami
Mohammed Gamgami - avatar
0
If you find James Gosling, ask this too. Why is there no multiple class inheritance in java? Isaiah Egbokhan
25th Sep 2019, 9:42 PM
Talha Altınel (The Last Sith Lord)
Talha Altınel (The Last Sith Lord) - avatar
0
i think it an oopsie
29th Sep 2019, 12:02 PM
Wwww