tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Arieh Markel <Arieh.Mar...@central.sun.com>
Subject RE: String/StringBuffer (was Re: An alternative to JSP)
Date Fri, 26 Jan 2001 18:35:06 GMT

> Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm
> list-help: <mailto:tomcat-dev-help@jakarta.apache.org>
> list-unsubscribe: <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
> list-post: <mailto:tomcat-dev@jakarta.apache.org>
> Delivered-To: mailing list tomcat-dev@jakarta.apache.org
> From: Michael.Smith@epiphany.com
> To: tomcat-dev@jakarta.apache.org
> Subject: RE: String/StringBuffer (was Re: An alternative to JSP)
> X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N
> X-MIME-Autoconverted: from quoted-printable to 8bit by amon.Central.Sun.COM id 
KAA15483
> 
> > 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. 
> 
> From this class: 
> 
> public class StringTest {
>   static String blah = "My " + "dog " + "has " + "fleas.";
> }
> 
> The following is the result from "javap -c StringTest" after compiling:
> 
> Compiled from StringTest.java
> public class StringTest extends java.lang.Object {
>     static java.lang.String blah;
>     static {};
>     public StringTest();
> }
> 
> Method static {}
>    0 ldc #1 <String "My dog has fleas.">
>    2 putstatic #5 <Field java.lang.String blah>
>    5 return
> 
> Method StringTest()
>    0 aload_0
>    1 invokespecial #4 <Method java.lang.Object()>
>    4 return
> 
> 

Michael,

thanks. I stand corrected.

Arieh

> regards,
> michael
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, email: tomcat-dev-help@jakarta.apache.org

--
 Arieh Markel		                Sun Microsystems Inc.
 Network Storage                        500 Eldorado Blvd. MS UBRM11-194
 e-mail: arieh.markel@sun.COM           Broomfield, CO 80021
 Let's go Panthers !!!!                 Phone: (303) 272-8547 x78547
 (e-mail me with subject SEND PUBLIC KEY to get public key)


Mime
View raw message