Yes, and also Nimisha Sinha was right. The following link was useful for me
to understand this behaviour, I hope it helps you too:
http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.10.5

The following is an excerpt of that chapter:

   - Literal strings within the same class
(§8)<http://java.sun.com/docs/books/jls/third_edition/html/classes.html#29542>in
the same package
   
(§7)<http://java.sun.com/docs/books/jls/third_edition/html/packages.html#29542>represent
references to the same
   String object
(§4.3.1)<http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#12028>.

   - Literal strings within different classes in the same package represent
   references to the same String object.
   - Literal strings within different classes in different packages likewise
   represent references to the same String object.
   - Strings computed by constant expressions
(§15.28)<http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#5313>are
computed at compile time and then treated as if they were literals.
   - Strings computed by concatenation at run time are newly created and
   therefore distinct.

Regards.


2009/7/20 miga <[email protected]>

>
>
>
> On Jul 20, 5:42 pm, Nimisha Sinha <[email protected]> wrote:
> > In Java,String literals are stored in a literal pool.If two string
> literals
> > are having same content,their references will be same too.
> Sorry, I was reading a little too quick.
>
> It seems that it is related to the way the line is interpreted. Since
> there is no parentheses in the second part it is probably viewes as:
> is the string a space plus s1 equals to s2, which is not, hence false,
> then the first part is true, and false plus true equals false.
> At least, it was what appears when playing with boolean object and
> parentheses.
> >
>


-- 
Jorge Ortalli

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to