Simple Java generics question: I have two classes – one of which uses generics to define its type, the other which extends this class providing a concrete type.
public class Box<Item> {
...
}
public class Toolbox extends Box<Tool>{
...
}
Given that Toolbox extends Box providing a Tool as the actual type for the generic placeholder, I would have thought it should be possible to do something like this:
Box<Tool> box = new Box();
Toolbox toolbox = box;
However, it seems this causes a type-mismatch. Why is this?
Box<Item>is the unbound generic type.Box<Tool>is a particular bound version of that same generic type.Toolboxis a subclass ofBox<Tool>and thus is a discrete type fromBox<Tool>.