This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Runtime constant pool

 
Madan, Gopal
Ranch Hand
Posts: 86
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The pool, with reference to String literals:
Is this pool, created/maintained by JVM
- on a per class basis?
- on a package basis? or
- for everything per JVM session
In JLS, in the section "3.10.5 String Literals", the code example output proves that a string literal has a unique reference from anywhere - class, same/different class(s), same/different package(s).
I guess, my question is :
Can i have the string literal "Hello" in any 2 different places and prove that they are not equal. I am trying to compare and contrast the code example in the section "3.10.5 String Literals" of JLS.
Thanks for any help
Madan
 
shweta agarwal
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check this code out:
class StringTest{
public static void main(String s[]){
String a=" hello";
String b=" hello";
if (a.equals(b))
System.out.println(" Same contents");
else System.out.println(" Different contents");
if (a==b)
System.out.println(" same object");
else System.out.println(" Different objects");
}
i think this will solve ur problem since if u declare the string b in the above manner then it will be the same object that will be referred to.but if u declare b as
String b=new Sring(" hello");
then u get different results.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic