aspose file tools*
The moose likes Beginning Java and the fly likes Help on == Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help on ==" Watch "Help on ==" New topic
Author

Help on ==

Ramon Haayema
Greenhorn

Joined: May 17, 2008
Posts: 14
hi everyone the following problem occource

System.out.println(LB.getRole());
System.out.println(LB.getUser());
System.out.println(LB.getProfile());
if ( LB.getRole() == "admin" ) { System.out.println("True");}
else { System.out.println("False " + LB.getRole());}
then the ouput is:

admin
Haayema, Ramon
exvgl
False admin

but the LB(Bean) getRole is admin,
what is that i ame missing.
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Hi Ramon,

you should always use the equals() method if you want to test the content of strings for equality!

The == operator test for object identity which is a different thing!

Marco
Ramon Haayema
Greenhorn

Joined: May 17, 2008
Posts: 14
System.out.println(LB.getRole());
System.out.println(LB.getUser());
System.out.println(LB.getProfile());
if (LB.getRole().equals("admin")) { System.out.println("True");}
else { System.out.println("False " + LB.getRole());}
}
still the same :
admin
Haayema, Ramon
exvgl
False admin
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

What exactly does getRole() return? Are there perhaps any invisible characters like line feed, tab, spaces etc.?
Ramon Haayema
Greenhorn

Joined: May 17, 2008
Posts: 14
Got it... did a trim on the setter in the bean class.
thankyou for helping.
 
jQuery in Action, 2nd edition
 
subject: Help on ==