Re: Invoking ArrayList.get() impossible with reflection ?
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
---910079544-1511079474-1221836963=:11982
Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8BIT
On Fri, 19 Sep 2008, S?bastien de Mapias wrote:
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 ?
It means you've passed the wrong number of arguments for the method you're
trying to invoke reflectively, not the invoke method itself.
List.get takes one argument, an integer, so when you call it with no
arguments, it doesn't work. If you pass in an integer, it will work.
Try:
int index = 0 ;
Object o = method.invoke(ref, index);
That will work.
It will fail for most of the other methods, since they have different
argument lists.
There's no straightforward way to invoke an arbitrary method so that it
will work. But why would you want to do that anyway?
tom
--
got a DOCTORATE in cold ROCKIN' IT
---910079544-1511079474-1221836963=:11982--