Today i had discussion with my colleague about casting.
Our case: We have root class
abstract class RootFoo<R extends RooFoo> {
...
abstract R getThis();
}
and we implement method getThis in subclasses.
To save (in my opinion) unnecessary implementation getThis method in every subclass i showed my solution:
abstract class RootFoo<R extends RooFoo> {
...
abstract R getThis() {
return (R) this;
}
}
Could you help me understand why my idea is wrong?