M
Michael Borgwardt
I'm currently using generics quite intensively and have run into a problem with
the following configuration:
class DataBase{}
class DataSub extends DataBase{}
class ControllerBase<D extends DataBase>{
void method(D d);
}
class ControllerSub<D extends DataSub> extends ControllerBase<D>{
void method(D d);
}
My Problem is I think that, due to type erasure, method() in ControllerSub
does not override method() in ControllerBase, it overloads it, i.e.:
class ControllerBase{
void method(DataBase d);
}
class ControllerSub extends ControllerBase{
void method(DataSub d);
}
The result is that client classes that know only about ControllerBase end up
calling method(DataBase) even when doing it with an instance of DataSub
through an instance of ControllerSub.
Any idea how to avoid this and still keep the type safety Generics provide as
much as possible?
the following configuration:
class DataBase{}
class DataSub extends DataBase{}
class ControllerBase<D extends DataBase>{
void method(D d);
}
class ControllerSub<D extends DataSub> extends ControllerBase<D>{
void method(D d);
}
My Problem is I think that, due to type erasure, method() in ControllerSub
does not override method() in ControllerBase, it overloads it, i.e.:
class ControllerBase{
void method(DataBase d);
}
class ControllerSub extends ControllerBase{
void method(DataSub d);
}
The result is that client classes that know only about ControllerBase end up
calling method(DataBase) even when doing it with an instance of DataSub
through an instance of ControllerSub.
Any idea how to avoid this and still keep the type safety Generics provide as
much as possible?