Page 1 of 1

About Question enthuware.ocpjp.v21.2.3096 :

Posted: Mon Oct 06, 2025 1:21 pm
by giginar
3 - public <T> ArrayList<T> transform(List<T> list) {     return new ArrayList<T>(); };

that works fine.but why these are not working?

1 - public ArrayList<Number> transform(List<Number> list) {     return new ArrayList<Number>(); };
2 - public ArrayList<Object> transform(List<Object> list) {     return new ArrayList<Object>(); };

Re: About Question enthuware.ocpjp.v21.2.3096 :

Posted: Tue Oct 07, 2025 2:12 am
by admin
Because the input parameter type in the base class's method is List<T>. What if the user of this method types it to some class XYZ?
In that case, the overriding method with List<Number> or List<Objective> will not be compatible with the base class's version.