Do not use assertions to validate arguments to a public method.

Do not use assertions to validate arguments to a public method.

Following code for the assertion : 

public void doStuff(int x) {
assert (x > 0);
// do things with x
}

A public method might be called from code that we don\'t control,because Because public methods are part of our exposed interface to the outside
world, we are supposed to guarantee that any constraints on the arguments will be enforced by the method itself. But since assertions aren\'t guaranteed to actually run.

By:UMANG
Date:2002-03-09 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related scjp1.5 chap4 Links

scjp1.5 chap4 interview questions and answers for experienced and fresher