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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
ETS User

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

Post 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

admin
Site Admin
Posts: 10384
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 8 guests