Invoking ArrayList.get() impossible with reflection ?
Hi,
I'm asking my question of 2 days ago another way today.
I have a class that contains the code:
~ Class<?> coll = Class.forName(ref.getClass().getName());
~ Method[] methods = coll.getDeclaredMethods();
~
~ for (Method method : methods)
~ {
~ method.setAccessible(true);
~
~ try {
~ Object o = method.invoke(ref, (Object[])null);
~ System.out.println("OK METHOD NAME "+method.getName());
~ } catch (java.lang.IllegalArgumentException iae) {
~ System.out.println("FAILS FOR "+method.getName());
~ }
~ }
My var 'ref' is a reference to a java.util.ArrayList<Something>.
I've tried the code above with
~ Object o = method.invoke(ref, (Object[])null);
and the 2nd argument of 'invoke' left to null:
~ Object o = method.invoke(ref);
I get the following in both cases (the *same* output):
~ OK METHOD NAME trimToSize
~ FAILS FOR ensureCapacity
~ OK METHOD NAME size
~ OK METHOD NAME isEmpty
~ FAILS FOR contains
~ FAILS FOR indexOf
~ FAILS FOR lastIndexOf
~ OK METHOD NAME clone
~ OK METHOD NAME toArray
~ FAILS FOR toArray
~ FAILS FOR get
~ FAILS FOR set
~ FAILS FOR add
~ FAILS FOR add
~ FAILS FOR remove
~ FAILS FOR remove
~ FAILS FOR fastRemove
~ OK METHOD NAME clear
~ FAILS FOR addAll
~ FAILS FOR addAll
~ FAILS FOR removeRange
~ FAILS FOR RangeCheck
~ FAILS FOR writeObject
~ FAILS FOR readObject
So the invocation of most methods of the ArrayList implementation
fails.
IMPORTANT: it fails with the error "wrong number of arguments".
How come ?? 'invoke()' can be called with one, or 2 args right ?
What am I missing here ?
Anybody has any idea why please ?
Please !
Thanks a lot...
S=E9bastien