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..
About Question enthuware.ocpjp.v8.2.1295 :
Moderator: admin
-
- Posts: 10
- Joined: Mon Aug 18, 2014 5:25 am
- Contact:
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1295 :
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.
(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.
-
- Posts: 7
- Joined: Tue Oct 04, 2016 6:11 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1295 :
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
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
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1295 :
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.
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.
Who is online
Users browsing this forum: Google [Bot] and 12 guests