Page 1 of 1

About Question enthuware.ocpjp.v8.2.1295 :

Posted: Mon Apr 11, 2016 4:52 am
by rvt1234
One of the answers it says that it compiles with a warning, however for me it compiles with 2 notes:

Note: XYZ.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Are we assuming during the exam everything is compiled with -Xlint:unchecked enabled?

Only after compiling with -Xlint:unchecked I get the warning..

Re: About Question enthuware.ocpjp.v8.2.1295 :

Posted: Mon Apr 11, 2016 8:26 pm
by admin
Although it does not use the word "Warning" in the message, the note is actually a warning. -Xlint option only provides more details and also uses the word warning but the issue is same.
(Here is a nice discussion about similar issue - http://stackoverflow.com/questions/1979 ... ns-warning )

No, in the exam you should not assume any such flags. If they want you to use the flags, the question will explicitly mention it.

HTH,
Paul.

Re: About Question enthuware.ocpjp.v8.2.1295 :

Posted: Tue Dec 20, 2016 8:39 pm
by elit3x
What is the correct method declaration for this?

I have tried ;
public void helpPeople(Queue<Person> people, Queue<Person> helped)
&
public void helpPeople(Queue<Person> people, Queue<String> helped)

But both get error. What am I doing wrong?

Thank you

Re: About Question enthuware.ocpjp.v8.2.1295 :

Posted: Wed Dec 21, 2016 12:17 am
by admin
The correct declaration is:
public void helpPeople(Queue<Person> people, Queue<Person> helped)
but the problem is because of the statement
helped.offer(p.getName());
This statement should also be changed to helped.offer(p);

This is the issue that is highlighted by this code. It shows why the code that does not use generic (i.e. uses type unsafe operations) is dangerous. It may compile but will fail at run time.

The moment you start using type safe declarations using generics, the compiler can show you problems that were hidden before.

HTH,
Paul.