== String vs. const String ==
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   laeticia_corlean
Posted On:   Friday, October 4, 2002 02:04 AM

Hi,


Is there a performance avantage using a "const String" rather than a simlpe "String" when dealing with string I know are not going to be modified by a class?


If not what is not goal of "const"


Thanks.

Re: == String vs. const String ==

Posted By:   Christopher_Koenigsberg  
Posted On:   Friday, October 4, 2002 07:47 AM

String objects are all immutable ("constant") anyway, in Java. That's why you are encouraged to use a StringBuffer instead, if you will be changing the string a lot, because otherwise with a String object, each change actually results in a whole new object.

Re: == String vs. const String ==

Posted By:   Didier_Blaise  
Posted On:   Friday, October 4, 2002 05:05 AM

"const" is a reserved keyword in Java, but is unused, and thus has nothing to do with the C++ "const" keyword.
If you want to avoid the change of a parameter, you can declare it as "final".
About | Sitemap | Contact