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>(); };
About Question enthuware.ocpjp.v21.2.3096 :
Moderator: admin
-
- Posts: 21
- Joined: Fri Feb 07, 2025 5:36 pm
- Contact:
-
- Site Admin
- Posts: 10433
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v21.2.3096 :
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.
In that case, the overriding method with List<Number> or List<Objective> will not be compatible with the base class's version.
Who is online
Users browsing this forum: No registered users and 165 guests