Home > DeveloperSection > Forums > Java Multiple Inheritance
Samuel Fernandes
Samuel Fernandes

Total Post:155

Posted on    November-05-2014 3:24 AM

 .NET Javafx  Inheritance 

 1 Reply(s)
 578  View(s)
Rate this:

I am working with the JavaFX Shape subclasses, and I have run into what I believe is a rather strange issue. My goal is to extend several of these shape subclasses (i.e. RectangleCircle) in order to add my own attributes to these objects. For example, the extension of the Rectangle subclass would look like this:

public class MyRectangle extends javafx.scene.shape.Rectangle 
    implements SpecialInterface {

    private SpecialAttributes specialAttributes;

Where the SpecialInterface can be used to specify the methods related to the new attributes that will be added to MyRectangle and MyCircle, in this case:

public interface SpecialInterface {

    public SpecialAttributes getSpecialAttributes();
    public void setSpecialAttributes();


However, when I try to create service classes that reference these subclasses of Rectangle and Circle, it seems as though I cannot do so generically. Essentially, the problem arises when I need to utilize attributes and methods from both the Shape subclasses and the SpecialInterface interface:

public class ManipulationService{

    public ManipulationService(<Undefined> myExtendedShape) {
        myExtendedShape.onRotate(new EventHandler<>(){



The issue here is that I cannot create a superclass for my extended shapes that would replace <Undefined> above. Specifically, if I create a superclass, I cannot extend the specific shapes that I want to extend in my subclasses due to a lack of multiple inheritance. If I replace <Undefined> with Shape, though, I then lose access to the methods in SpecialInterface.

I'm sure that this sort of multiple-inheritance problem has been solved before, but I cannot find the solution. I appreciate any and all suggestions on how to handle this situation.

Simons Hood
Simons Hood

Total Post:70

Posted on    November-05-2014 5:19 AM

You can define ManipulationService like this:

class ManipulationService<T extends Shape & SpecialInterface> {
    public ManipulationService(T myExtendedShape) {
        myExtendedShape.onRotate(/* ... */);

Don't want to miss updates? Please click the below button!

Follow MindStick