What are my options, if I what the following code to work?
class Garage<X>{}
class Vehicle {}
class Car extends Vehicle {}
class Bike extends Vehicle {}
class A {
public static void main(String[] args) {
Garage<Car> car = new Garage<>();
Garage<Bike> bike = new Garage<>();
Garage<Vehicle> vehicle = new Garage<>();
//what are the options to do this?
vehicle=car;
vehicle=bike;
}
}
What I'm after is to try upcast(?) car and bike to vehicle. Is this even possible with this kind generic class type?