[HD-OCP17/21-Fundamentals Pg 0, Sec. 16.2.2 - using-lower-bounded-wildcard]

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

Moderator: admin

Post Reply
joaoclopes
Posts: 35
Joined: Mon Sep 23, 2024 4:49 pm
Contact:

[HD-OCP17/21-Fundamentals Pg 0, Sec. 16.2.2 - using-lower-bounded-wildcard]

Post by joaoclopes »

Hello,

In the code example:

Code: Select all

void loadValuesFromDB(List<? super Number> targetList){
  //for(Number value : targetList){ ... }//will not compile
  //values.add("hello"); //will not compile
  values.add(1.0); //fine
}
Shoudn't it be:

Code: Select all

void loadValuesFromDB(List<? super Number> targetList){
  //for(Number value : targetList){ ... }//will not compile
  //targetList.add("hello"); //will not compile
  targetList.add(1.0); //fine
}
Thanks!

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

Re: [HD-OCP17/21-Fundamentals Pg 0, Sec. 16.2.2 - using-lower-bounded-wildcard]

Post by admin »

Yes, it should be targetList.

thank you for your feedback!

joaoclopes
Posts: 35
Joined: Mon Sep 23, 2024 4:49 pm
Contact:

Re: [HD-OCP17/21-Fundamentals Pg 0, Sec. 16.2.2 - using-lower-bounded-wildcard]

Post by joaoclopes »

No problem! Glad that I could help!

Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests