0

I'm wanting to use Java reflection to call a method on a class of mine that has the following signature:

public Object execute(Object...params)

In my loader class, I have the class loaded, but I'm not sure how to setup my getMethod call. Currently, I have something like this:

Method classEntry = _loadedClass.getMethod("execute", new Class[]{Object[].class});

I then try to invoke this method after creating a newInstance of my class by calling:

Object classObj = _loadedClass.newInstance();
classEntry.invoke(classObj, params); // params comes in from the method as Object...params

This is giving me a java.lang.NoSuchMethodException Exception. I know that my issue lies in my getMethod call. How should I set that up to accept a params object?

1 Answer 1

2

If params is of type Object [] then you need to call invoke like this:

classEntry.invoke(classObj, new Object [] {params});

But this does not explain NoSuchMethodException

Sign up to request clarification or add additional context in comments.

1 Comment

That fixed it! Adding that in fixed everything. I love quick fixes! Thanks again!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.