Page 1 of 1

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

Posted: Sun Jan 12, 2025 11:15 am
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!

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

Posted: Sun Jan 12, 2025 10:58 pm
by admin
Yes, it should be targetList.

thank you for your feedback!

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

Posted: Mon Jan 13, 2025 7:21 pm
by joaoclopes
No problem! Glad that I could help!