dimanche 30 avril 2017

Creating Subclass via Reflection

I'm trying to create either a subclass of a class, or even just create an instance of that class and override 1 method using reflection.

The class is called EntityRenderer, and i have no other way of accessing it except using reflection. I can access the class fine and create new instances, but i'm not sure how to create a new instance with an overriding method.

As an example. If i was to do this non-reflection i would do something like:

EntityRenderer renderer = new EntityRenderer() {
    @Override
    public void overridenMethod(Parameters) {
        // Handle method
    }
};

My end goal is to change 1/2 variables that are in the method. E.g. double d = 1.0 to double d = 2.0.

I tried to use ClassFileTransformers but for some reason the class i'm looking for is never parsed by the transformer...

I've heard this isn't possible with pure Reflection. As such, i'm willing to use an API such as Javassist to 'assist' with this goal.

Thanks for your help!





Aucun commentaire:

Enregistrer un commentaire