Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

assert with ternary operator

 
Shwetha Sharma
Ranch Hand
Posts: 34
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Source : http://www.etattva.com/

The explaination says :
Compilation error because Here ternary operator & augmented form of assertion are used in a wrong way. Syntex of ternary operator is <Boolean exp>?<msg>:<msg> In augmented form of assertion, syntax is, assert <Boolean expression> : <msg expression> If we write it as assert (a > 0) ? <Boolean exp> : <Boolean exp>; then it will compile .

I am not clear with the bold part.For eg if we use it as follows:
int a=0;
assert (a > 0) ? true : false;

what is the above code doing ??
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
assert (a > 0) ? true : false; is just a roundabout way of saying:
assert a>0;
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic