Article View: borland.public.jbuilder.java.language
Article #612Reflection on invoking methods
From: Aven
Date: Tue, 29 Mar 2005 02:45
Date: Tue, 29 Mar 2005 02:45
21 lines
1635 bytes
1635 bytes
Hi,
I am trying to invoke methods using reflection, i.e., given an object, a
method name
and an array of arguments, find out a Method object that corresponds to the
method,
then invoke the method. Problems arise as follows.
1. How to deal with primitive argument types ?
for example, if the method is foo(int a, int b);
the arguments are passed as new Object[]{10,20},
however, the method was not found because of autoboxing.
( I have tried redefine foo as foo(Integer a, Integer b). That works
fine. )
How to pass the primitive types?
2. How to search varargs methods smartly?
Currently I have to get all methods using Class.getMethods()
Then check the parametertypes of every method. It is not efficient.
Thank you very much!
-Aven
Technical Details
Message-ID:
<4248c14d$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!feed.news.schlund.de!schlund.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: f74b3,837487ca0499b687,start X-Google-Attributes: gidf74b3,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Aven" <aven_02@yahoo.com> Newsgroups: borland.public.jbuilder.java.language Subject: Reflection on invoking methods Date: Mon, 28 Mar 2005 18:45:42 -0800 Lines: 23 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 NNTP-Posting-Host: 128.111.68.241 Message-ID: <4248c14d$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1112064333 128.111.68.241 (28 Mar 2005 18:45:33 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!npeer.de.kpn-eurorings.net!feed.news.schlund.de!schlund.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail