Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.222 :

Posted: Fri Jun 15, 2012 3:50 am
by ETS User
public class TestClass
{
public static void main(String[] args)
{
assert args.length == 2 : "Must give two arguments";
...
}
}
right answer "The programmer should throw a RuntimeException instead of using an assertion in this case"

I choosed "This is an appropriate use of assertions."
Weird... the book state
Don't Use Assertions to Validate Command-Line Arguments
Don't Use Assertions to Validate Arguments to a Public Method

Re: About Question com.enthuware.ets.scjp.v6.2.222 :

Posted: Fri Jun 15, 2012 5:51 am
by admin
Here, the code is using assertion to validate argument to a method, which is not advisable. Therefore, the given answer is correct.

HTH,
Paul.