Note that Class#getMethod()
has two parameters: a String
and an vararg of Class
objects. The former is
the list of parameters
that the method declares.
You need to use
ArrayList.class.getMethod("get", int.class);
since the ArrayList#get(int)
method has an int
parameter.
I initially missed the whole
ArrayList.class.getClass().getMethod("get")
^ ^
| |----------------------------- gets Class<Class>
|----------------------------------- gets Class<ArrayList>
The .class
already gets the Class
instance for ArrayList
. Calling getClass
on that will return the Class
instance for class Class
. You don't want that.