The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Comparing Globalized Variables

Posted by Avin Sinanan on November 29, 2001 at 2:53 PM

Is it possible to Compare golbalized variables.. ie use them in If/Else Statements??

for example i have globalized some variables using the flowing class

class Global
{
public static String name1 ;
public static String name2 ;

}


And later on in other classes when i call these local classes
eg. later on i used the folling statements in anther class....

if(Global.name1==Global.name2)
{
System.out.println("same");
}
else
{
System.out.println("diff");
}

Where Global.name1 and Global.name2 were defined in two other totally seperate classes as "

Global.name1 = "hello";

and
Global.name2 = "hello";

note that they are the same strings.. they have the same value
..and when the program loads it prints "diff" becasue of the if and else statements shown before. They never print same..why is this?



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us