Why String class is declared as final in Java?

Julian Clark | 2023-05-05 14:10:00 | page views:1090
I'll answer
Earn 20 gold coins for an accepted answer.20 Earn 20 gold coins for an accepted answer.
40more

Caleb Wright

Works at Oracle, Lives in Redwood City, CA
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).
2023-05-10 14:10:00

Zoe Young

QuesHub.com delivers expert answers and knowledge to you.
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).
ask:3,asku:1,askr:137,askz:21,askd:152,RedisW:0askR:3,askD:0 mz:hit,askU:0,askT:0askA:4