Re: String literal
On Jul 24, 7:42 am, stef <stef.pellegr...@gmail.com> wrote:
Ok,
My way of thinking was wrong (I'm a stubborn C++ programmer)
I just didn't really think about "Hello world" as an object.
String is a reference type and is clearly documented as such.
Javadocs:
public final class String
extends Object
implements Serializable, Comparable<String>, CharSequence
<http://java.sun.com/javase/6/docs/api/java/lang/String.html>
JLS:
A string literal is always of type String (=A74.3.3).
A string literal always refers to the same instance (=A74.3.1) of class S=
tring.
<http://java.sun.com/docs/books/jls/third_edition/html/
lexical.html#3.10.5>
and
"4.3 Reference Types and Values"
<http://java.sun.com/docs/books/jls/third_edition/html/
typesValues.html#4.3>
includes
"4.3.3 The Class String"
<http://java.sun.com/docs/books/jls/third_edition/html/
typesValues.html#4.3.3>
Then of course there's the Java tutorial:
The String class is not technically a primitive data type,
and
<http://java.sun.com/docs/books/tutorial/java/data/index.html>
In the Java programming language, strings are objects.
with a link to more detail:
In this case, "Hello world!" is a string literal
=97 a series of characters in your code that is enclosed in double quotes=
..
Whenever it encounters a string literal in your code, the compiler
creates a String object with its value=97in this case, Hello world!.
With all that information provided at the very beginning of the Java
learning curve, one should never make the mistake that they 'just
didn't really think about "Hello world" as an object.'
--
Lew