abstract class Vehicle
{
void collide(Vehicle v){}
}
class Car extends Vehicle
{
@Override
void collide(Vehicle v){super.collide(v);}
}
class Truck extends Vehicle
{
@Override
void collide(Vehicle v){super.collide(v);}
}
如果我执行以下操作:
@Inject
Vehicle vehicle;
@Inject
如何知道要实例化哪个对象?- 我认为这会抛出一个
AmbiguousResolutionException
异常,我错了吗?
我想这样做是为了避免这个问题,同时也可以专门处理参数,但这是不被允许的,我理解 原因。
class Car extends Vehicle
{
@Override
void collide(Car v){super.collide(v);}
}
class Truck extends Vehicle
{
@Override
void collide(Truck v){super.collide(v);}
}
什么是解决方法(workaround)?