Skip to main content
Post Closed as "Not suitable for this site" by Antot, t3chb0t, Graipher, Heslacher, Toby Speight
deleted 9 characters in body
Source Link

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?

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?

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> {
   ...
   R getThis() {
       return (R) this;
   }
}

Could you help me understand why my idea is wrong?

Source Link

Java inheritance and generics

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?