Why can I not add sub class as user data when super class implements Savable?

Hey dear community,

I noticed that I cannot add sub classes as user data, whose super class implements the Savable Interface.

Let’s say I have the class A as follows:

public class A implements Savable {

    @Override
    public void write(JmeExporter ex) throws IOException {        }

    @Override
    public void read(JmeImporter im) throws IOException {        }

}

And the class B which extends class A:

public class B extends A {

    @Override
    public void read(JmeImporter im) throws IOException {
        super.read(im); 
    }

    @Override
    public void write(JmeExporter ex) throws IOException {
        super.write(ex); 
    }
}

In the SDK I cannot add class B as user data even though it is an instance of Savable, or not?

I would really like it, if someone could comment on that.

Greetings,
Domenic

Probably because it checks or immediate implementation and doesn’t do an isAssignableFrom() check.

On some level, that’s probably ok because often subclasses will add data and nothing requires them to directly implement those methods. Perhaps the thinking was that force the user to add an implements Savable to the subclass might make them think about the additional data in the extension.

And I think most people don’t use Savable like this so haven’t hit it. It’s usually used for non-complex stuff I guess.

Hey @pspeed, thanks for your answer. Yes, I also thought about that. I personally don’t need it, it is just something I randomly noticed :slight_smile: