Issue
I am trying to get a method of a class I load during runtime using Class.getDeclaredMethod
. The parameters for Class.getDeclaredMethod
are String name, Class<?>... parameterTypes
. I have the parameterTypes
as a List.
How do I pass the parameterTypes
from my list to the Class.getDeclaredMethod
?
I tried (Class[]) paramterTypes.toArray()
and it didn't work.
Solution
You are almost there. It is simply
Class[] paramsAr = new Class[parameterTypes.size()];
parameterTypes.toArray(paramsAr);
Answered By - ControlAltDel
Answer Checked By - Marie Seifert (JavaFixing Admin)