Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Why aren't these equal?

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now, I am trying to compare the boolean equality to the .equals method. Here is the relevant code:



Now, here is the output upon running:

false
line 03 output

snake.equals(frog) ? true
line 04 output

false
line 06 output

false
line 07 output

dog.equals(frog) ? true
line 08 output

dog.equals(snake) ? true
line 09 output

false
line 13 output

false
line 14 output

false
line 15 output

Now, my confusion comes from the output of lines 06 and 15. Is it not true that if you use the equal sign to assign one variable as equal to another they will have the same reference, and will hence be "boolean equal?"

In addition, why is it that when I print out a boolean equality the string preceding it is not printed?

Thank You for Responding:

Andrew Stallard


 
Sheriff
Posts: 67592
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.difranco.net/cop2551/java_op-prec.htm
 
Andrew Stallard
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:http://www.difranco.net/cop2551/java_op-prec.htm



OK, I've got it. You need parenthesis around the boolean equality.

 
Bear Bibeault
Sheriff
Posts: 67592
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bingo. Your tests weren't testing what you thought they were.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic