🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #614

Re: Reflection on invoking methods

#614
From: Shankar Unni
Date: Tue, 29 Mar 2005 19:38
25 lines
1919 bytes
Aven wrote:

> 1. How to deal with primitive argument types ?

You make an object out of it.

>    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.

If the method was *defined* as taking an "int" (as above), then 
reflection will show its parameter type as == "int.class". (There are 
nine predefined Class objects to represent the eight primitive types and 
void).

To pass an actual parameter for these types, just pass in an "Integer" 
or a "Double" or whatever the equivalent Object type is.

> 2. How to search varargs methods smartly?

Method.isVarArgs().

The last formal parameter (according to the reflection API) for varargs 
methods will be an Object[] array - you pass all the variadic arguments 
in that array.
Technical Details
Message-ID: <4249ae9a$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!nntp.abs.net!news-FFM2.ecrc.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4248c14d$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,837487ca0499b687
X-Google-Attributes: gidf74b3,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Tue, 29 Mar 2005 11:38:03 -0800
From: Shankar Unni <shankarunni@netscape.net>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050317 Thunderbird/1.0.2 Mnenhy/0.7
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language
Subject: Re: Reflection on invoking methods
References: <4248c14d$1@newsgroups.borland.com>
In-Reply-To: <4248c14d$1@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 68.120.146.125
Message-ID: <4249ae9a$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1112125082 68.120.146.125 (29 Mar 2005 11:38:02 -0800)
Lines: 25
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!nntp.abs.net!news-FFM2.ecrc.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail