File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "assert with ternary operator" Watch "assert with ternary operator" New topic

assert with ternary operator

Shwetha Sharma
Ranch Hand

Joined: Jun 01, 2008
Posts: 34

Source :

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.
I agree. Here's the link:
subject: assert with ternary operator
It's not a secret anymore!