aspose file tools*
The moose likes Beginning Java and the fly likes Assertions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Assertions" Watch "Assertions" New topic
Author

Assertions

sweety singh
Ranch Hand

Joined: Dec 15, 2007
Posts: 49
hi...
1. i wanted to know if both the following declaration for enabling and disabling the assertions at runtime are correct.
java -ea com.geelcsanonymous.Foo and
java -ea:com.geeksanonymous.Foo

2. can anyone give me an example for not using assertions to validate command line arguments.

3. i have not understood this:

code:

switch(x) {
case 2: y = 3;
case 3: y = 9;
case 4: y = 27;
default: assert false; // We're never supposed to get here!
}
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38851
    
  23
I shall only answer one of your questions, the third. You have fall-through in that "switch" so you will reach the default.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Originally posted by sweety singh:
2. can anyone give me an example for not using assertions to validate command line arguments.


Dunno what you mean by an example. I can give reasons, if that's what you mean.

Assertions are for checking internal assumptions and consistency of a program. The conditions checked by assertions should be ones that are always true, unless there is a bug in the program.

Assertions are not for checking user input, resource availability, I/O success etc. Remember that assertions are turned off in release code, so if they were used for such checks, the checks would not happen in release code.

Command-line arguments are user input. Bad command-line arguments are not a bug in the program that's reading them. Therefore assertions should not be used for checking them.


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Assertions