I'm trying to wrap my head around this inheritance problem I'm having. Here's my current situation:

So I have a planning that can be either a list of activities (class Activities) or a list of things to do (class Todos).
However, if I do this in Todos:
private List<Todo> todos;
public List<Activity> getPlanning(){
return todos;
}
It says that the types are incompatible.
Since Todo extends from Activity, aren't we certain that Todo provides at least the same functionality as Activity?
and perhaps more importantly:
(I'm not an expert in UML so forgive me if there are some mistakes in my diagram)
Welcome to the nightmare and poor implementation of generics in Java. Try using public List<? extends Activity> getPlanning().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With