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?
About Question enthuware.ocpjp.v11.2.3378 :
Moderator: admin
-
- Posts: 18
- Joined: Fri Feb 05, 2021 3:37 am
- Contact:
About Question enthuware.ocpjp.v11.2.3378 :
Last edited by minajev3 on Sun Apr 11, 2021 2:56 am, edited 1 time in total.
-
- Site Admin
- Posts: 10113
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v11.2.3378 :
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) .
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.
-
- Posts: 18
- Joined: Fri Feb 05, 2021 3:37 am
- Contact:
Re: About Question enthuware.ocpjp.v11.2.3378 :
<> - that I experimented a bit.
But without it it compiles and runs without any warnings.
But without it it compiles and runs without any warnings.
-
- Site Admin
- Posts: 10113
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v11.2.3378 :
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.
Who is online
Users browsing this forum: No registered users and 12 guests