tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael.Sm...@epiphany.com
Subject RE: String/StringBuffer (was Re: An alternative to JSP)
Date Fri, 26 Jan 2001 17:02:30 GMT
> Last paragraph in the java.lang.String javadoc says:
> 
> The Java language provides special support for the string 
> concatentation operator
> ( + ), and for conversion of other objects to strings. String 
> concatenation is
> implemented through the StringBuffer class and its append 
> method. String
> conversions are implemented through the method toString, 
> defined by Object and
> inherited by all classes in Java. For additional information 
> on string concatenation
> and conversion, see Gosling, Joy, and Steele, The Java 
> Language Specification. 

And the Java Language Specification (Section 3.10.5: String Literals) says
this:

"Strings computed by constant expressions (ยง15.27) are computed at compile
time and then treated as if they were literals"

http://java.sun.com/docs/books/jls/html/3.doc.html#101083


> > 	Just thought that I would point out that: 
> > "My " + "dog " + "has " + "fleas." will be compiled as one String:
> > "My dog has fleas." and incurs no runtime penalties.  In the case
> 
> Paul,
> 
> Actually, my investigations in the past have shown that (at least in
> Sun's JDK 1.2) this is implemented as:
> 
> new StringBuffer 
> ("My").append("dog").append("has").append("fleas").toString();

If this is actually the case, Sun's JDK is not in compliance with the spec.
However, in my tests, this is not the case. 

Mime
View raw message