If I have a class called Cue that implements Tickable. Later, I have an observable list like so: ObservableList<Cue> oList. oList implements Iterable<Cue> (that's just how ObservableList is declared).
I have a function that takes Iterable<Tickable>. How do I get it to accept ObservableList<Cue> Cue is a Tickable and ObservableList is a Iterable. For some reason, I can't caste between them or upcast automatically. Is there any way to do this?
You cannot cast from an Iterable<Cue> to an Iterable<Tickable>, because even though a Cue is a Tickable, an Iterable<Cue> is not an Iterable<Tickable>, because Java's generics are invariant.
To have a method accept an ObservableList<Cue>, have the method parameter type be an Iterable<Cue> or use a bounded wildcard -- an Iterable<? extends Tickable>.
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