aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes assert with ternary operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "assert with ternary operator" Watch "assert with ternary operator" New topic
Author

assert with ternary operator

Shwetha Sharma
Ranch Hand

Joined: Jun 01, 2008
Posts: 34

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 ??


SCJP6:80%, OCWCD 88 %
Ruben Soto
Ranch Hand

Joined: Dec 16, 2008
Posts: 1032
assert (a > 0) ? true : false; is just a roundabout way of saying:
assert a>0;


All code in my posts, unless a source is explicitly mentioned, is my own.
 
wood burning stoves
 
subject: assert with ternary operator