This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
for == at line 1 there wont be any compiler error as there are in same hierachy whereas it occurs if there is no inheritence relationship like String,StringBuffer... thats fine.. but for equals method if there are in hierarchy they still return false ... like in the below code..
All objects are stored on the heap. A reference to the String object is stored in the constant pool (along with the characters contained in the literal). [ October 25, 2005: Message edited by: Steve Morrow ]
Joined: Sep 14, 2005
#Steve no only one on the Heap s2 ist placed on the stack and references directly the pool. the proof for this is that s2==s2.intern() returns TRUE, which would NEVER BE the Case if u used new String() --------------------
hmm, i think i know what u r talking about , but that is not the case/question. The s1 and s2 r simple(no frills) Strings so what is th output?
false true true false or false true false true or ...
for example 1 and 2 [ October 25, 2005: Message edited by: Ner min ]
Joined: Jul 28, 2005
ner .. regarding first one.. it prints false true true true.. second false true false true ..
coz..s1.intern means it will check in the pool whether this string exists (as equals) and if it finds then it will return that string .. s2=s1.intern(); will return the string and assign it to the same one which is already in the pool..so there wont be any shift ...
Joined: Sep 14, 2005
#srikanth, right, u know all that , how comes that u get confused with u'r initial question?
Originally posted by Ner min: #Steve ok there was misunderstending of term "object", strictly in javatermms saying objects r really in the one and only place, the HEAP. I just mixed the "objects" and "objects representations"
No problem. I was probably being entirely too nitpicky, anyway...