Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

very weird results from ternary operator...  RSS feed

 
Vinnie Jenks
Ranch Hand
Posts: 207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a ternary comparison that returns false no matter what I provide it and it makes absolutely no sense!

My code:



While debugging, "props.getProperty("is_locally_connected")" returns "true" (string, not boolean) yet isLocal always returns false once the code runs!

Am I loosing my mind? I've gotta be missing something from 24 straight hours of coding...I need someone to point out my stupidity here even though I've written these types of statements at least a billion times...

Thanks!
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or this:
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66208
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is not with the ternary operator but with your understanding of what the == operator does.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!