• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Strange Assertion Behaviour

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the following example from Dan Chisolm:



I would have thought that this wouldn't compile because the expression i1 = j1 + x1 doesn't return a boolean, it returns an int. I thought that the assert() method needed to receive a boolean. So what is going on here? I'm a little confused.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The complete expression is (i1 = j1 + x1) < 6; which does return a boolean.
[ February 10, 2006: Message edited by: marc weber ]
 
Ranch Hand
Posts: 193
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arthur-

You're right that (i1 = j1 + x1) doesn't return a boolean, but (i1 = j1 + x1) < 6 does. It's saying "assign i1 the value of j1 plus x1 and then compare the result to see if it's less than 6.

(i1 = j1 + x1) < 6

translates to

result of addition assigned to i1 compared with 6

and that evaluates to a boolean.

Josh
 
Arthur Blair
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
clearly my brain isn't working today. Thanks guys.
 
reply
    Bookmark Topic Watch Topic
  • New Topic