About Question enthuware.ocpjp.v8.2.1295 :

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

Moderator: admin

Post Reply
rvt1234
Posts: 10
Joined: Mon Aug 18, 2014 5:25 am
Contact:

About Question enthuware.ocpjp.v8.2.1295 :

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

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

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

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

elit3x
Posts: 7
Joined: Tue Oct 04, 2016 6:11 pm
Contact:

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

Post 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

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

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

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

Post Reply

Who is online

Users browsing this forum: vs2013 and 20 guests