jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Assertions 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 "Assertions" Watch "Assertions" New topic


Vishal Arora

Joined: Jul 29, 2005
Posts: 9
Here is the code given below. My question is that will it compile with assertions enabled.In my view it should not since statement //1 will be unreachable if asssertions are enabled. I tried to compile with assertions enabled and it compiled fine. But i am not able to undestand why.

[ August 03, 2005: Message edited by: Barry Gaunt ]
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Having Assertions enabled or disabled should never effect a program such that one line of code runs where another wouldn't based on it being enabled or not.

The compiler will not take those lines into account in determining if a line will run or not.

When an AssertionError occurs the application will stop, not continue on anyway, just like as if you issued a System.exit(0);


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Rick O'Shay
Ranch Hand

Joined: Sep 19, 2004
Posts: 531
So you believe this should not compile with assertions enabled. Not an unreasonable assumption but that's never the case. Compile time expression values can only produce unreachable code in while, for and do statements. That way you can say if(SKIP_FLAG) ... and not have it compile in one state and not in the other. Not particularly orthogonal but useful nevertheless.

The rationale is that you can have a constant
I agree. Here's the link: http://aspose.com/file-tools
subject: Assertions
It's not a secret anymore!