Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

string class

 
Saral Saxena
Ranch Hand
Posts: 203
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,

What's the technical reason of keeping the string class as final..??
 
Stephan van Hulst
Bartender
Pie
Posts: 5813
61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So people can't extend it. Is there anything you'd like to add to the String class?
 
Saral Saxena
Ranch Hand
Posts: 203
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:So people can't extend it. Is there anything you'd like to add to the String class?



Hi ,

I want to know, the technical reason...does it related to string pool..utilization also..?
 
Stephan van Hulst
Bartender
Pie
Posts: 5813
61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason is that there's no point in extending String. String conceptually doesn't have any subtypes.
 
Henry Wong
author
Marshal
Pie
Posts: 21123
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

There are a few reasons -- but if I had to guess, I would say that security is probably a big one.

Imagine an applet trying to open a network connection. Applets, by default, can only go back to the originating source. So, when an applet tries to open a connection, the host is passed to the security manager for approval prior to opening the connection. If the String class weren't final, you can override the class to behave a certain way during the security check, and behave in another later.

Henry
 
Winston Gutkowski
Bartender
Pie
Posts: 10417
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saral Saxena wrote:I want to know, the technical reason...does it related to string pool..utilization also..?

Saral, I really think you should read the tutorials (or a good book) rather than just machine-gunning this site for ready-made answers to whatever question you have this hour.

ShowSomeEffort (←click).

Winston
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15286
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another important reason is because class String is immutable. If it were not final, then somebody could make a subclass of String that has mutable state, and it wouldn't be immutable anymore.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic