I don't really know how to explain the problem I have. Below is an example of a few objects I have.
Lets say I have classes
public class Foo{}
public class FooBar extends Foo{}
All of that is fine, however if I take a list and say I want it to be full of Foo
objects, I cannot provide it a FooBar
object. Why is this?
Example:
List<Foo> fooList = Arrays.asList(new FooBar());
If FooBar extends Foo
, why cant it be cast back to Foo
?