Amol Brid
Posts: 43
Nickname: amolbrid
Registered: Feb, 2004
|
|
Re: Passing pimitive types as parameter to a function
|
Posted: Dec 2, 2004 4:33 AM
|
|
Hi Rajeev,
For premitive type the value of the Wrapper object of same type is taken. The statement which you have written is correct, check if the method exists with the same signature.
Here is my code which i used to cross check:
package com.amol;
import java.lang.reflect.*;
public class RefMethodEx
{
public void testBool(boolean flag)
{
System.out.println("testBool");
}
public static void main(String args[])
{
try
{
RefMethodEx methobj = new RefMethodEx();
Class cls = Class.forName("com.amol.RefMethodEx");
Class boolpara[] = new Class[1];
boolpara[0] = Boolean.TYPE;
Method boolm = cls.getMethod("testBool", boolpara);
Object boolarg[] = new Object[1];
boolarg[0] = new Boolean(true);
boolm.invoke(methobj, boolarg);
}
catch (Throwable e)
{
System.err.println(e);
}
}
}
Amol Brid
|
|