Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String ".equals" method always returning true?

 
Billy Nicholson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know where to go from here. Anything I could check?



I press any button which triggers an ActionEvent and I get:

Show/Hide Slave
Show/Hide Slave equals Show/Hide Slave
Show/Hide Slave equals Map

as the output.

Edit: Not only is it always returning true, it is also ignoring if/else flow.
 
Unnar Björnsson
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
remove the semicolon at the end of line 11
 
Billy Nicholson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.....*facepalm* Woooow... I feel like an idiot. Thanks a bunch.
 
Unnar Björnsson
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Billy Nicholson wrote:.....*facepalm* Woooow... I feel like an idiot. Thanks a bunch.


No reason to feel silly, I think this is actually a common mistake and easy to overlook
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15284
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that a semi-colon by itself is an empty statement. So line 11 of your code means "if command equals "Map", then do nothing" - and the block in lines 12 - 18 is completely separate from the if-statement and is always executed.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic