About Question enthuware.ocpjp.v11.2.3378 :

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

Moderator: admin

Post Reply
minajev3
Posts: 18
Joined: Fri Feb 05, 2021 3:37 am
Contact:

About Question enthuware.ocpjp.v11.2.3378 :

Post by minajev3 »

static void doElements(List l) {
l.add("abc");
}
public static void main(String[] args) {
List<Integer> l = new ArrayList<Integer>();
doElements(l);

System.out.println(l);
}

output [abc]


I tried as hard as I can but cant get that warning. Or I am missing something? but I am more amazed that it did add String to Integer List and works without exception. Whaaat?
Last edited by minajev3 on Sun Apr 11, 2021 2:56 am, edited 1 time in total.

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

Re: About Question enthuware.ocpjp.v11.2.3378 :

Post by admin »

That's because the code you have written above is different from the one given in the problem statement.
The code that you have written above doesn't compile.
Problem statement has static void doElements(List l) , while you have static void doElements(List<> l) .
If you like our products and services, please help us by posting your review here.

minajev3
Posts: 18
Joined: Fri Feb 05, 2021 3:37 am
Contact:

Re: About Question enthuware.ocpjp.v11.2.3378 :

Post by minajev3 »

<> - that I experimented a bit.
But without it it compiles and runs without any warnings.

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

Re: About Question enthuware.ocpjp.v11.2.3378 :

Post by admin »

Not sure how you are compiling but I get the following message upon compilation from the command line:

Code: Select all

Note: TestClass.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 4 guests