This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help on ==

 
Ramon Haayema
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly does getRole() return? Are there perhaps any invisible characters like line feed, tab, spaces etc.?
 
Ramon Haayema
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it... did a trim on the setter in the bean class.
thankyou for helping.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic