r/javahelp•
kvxdev

A partially known inheritance

Direct to the point: If you have class A, B and C, B and C inheriting A, is there a way to make a class D inherit B OR C (not multiple inheritance)? A kind of inverted generic? Thanks for your time.

Posted Dec 8, 2017, 9:50 PM UTC

12
nutrechtJava Dev•

Can you explain what problem you're trying to solve?

Class D can implement multiple interfaces, even if they have overlap. This sounds closest to what you're asking.

1
kvxdevOP•

A graphical library containing a class A (Spacial), B (Geometry) and C (Node). For a theoretical D extends<T extends Spatial> (I know doesn't exist) for shared functionalities between their further child. We would have inserted that into A if we could have.

-Edit-

To be fair, this question is half academic. There are work-arounds, multiple. But since this question does not violate the multiple inheritance nor cuz issue at "compile" time, I'm very curious since it seems like there should be some way to do so.

1