vendredi 17 avril 2020

Java reflection with arbitrary classes and methods

The problem I have is: I am loading several classes and testing methods at runtime. The problem I have is, the input is an arbitrary amount of classes.

ClassOne, with methods ClassOne.foo() and ClassOne.bar(), but I have another class:

ClassTwo, with method ClassTwo.foobar()

and each has their respective constructors.

I'm taking an input of method names, their inputs and their expected outputs, what is the best approach to running these methods.

One approach could be to just have the classnames in a list, which I create an object of, then loop through the method list and call the method. This would require checking the method name each time e.g current object is ClassOne, so only call methods with 'ClassOne.' present. The method names will always contain the class they're apart of as prefix.

This is my first time using reflection so maybe I'm going about this all wrong, any help is appreciated





Aucun commentaire:

Enregistrer un commentaire