Home arrow static arrow Java Programming [Archive] - Using reflection & varargs JDK 1.5
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Using reflection & varargs JDK 1.5
This topic has 1 reply on 1 page.

Posts:1
Registered: 7/15/04
Using reflection & varargs JDK 1.5  
Jul 15, 2004 9:31 AM



 
Hi all,

I would like to instantiate an object using reflection and JDK 1.5. The problem is that the input parameters of the constructor are varargs.

When I execute the following code I get a "java.lang.IllegalArgumentException: wrong number of arguments" exception.

Anybody got a clue?

Class[] cl = {Object[].class};
Object[] objs = {hostName, port, null, env.getProperty (dermi.Context.PROTOCOL)};
String className = "dermi.core.DermiConnection";
connection = (DermiConnection) Class.forName (className).getConstructor (cl).newInstance (objs);

The constructor's signature is:

public DermiConnection (Object ... args) throws ConnectionException { }

Thanx in advance.

--

Carles.
 

Posts:27,518
Registered: 11/3/97
Re: Using reflection & varargs JDK 1.5  
Jul 15, 2004 1:07 PM (reply 1 of 1)



 
Hi all,

I would like to instantiate an object using reflection
and JDK 1.5. The problem is that the input parameters
of the constructor are varargs.

When I execute the following code I get a
"java.lang.IllegalArgumentException: wrong number of
arguments" exception.

Anybody got a clue?

Try this...

Class[] cl = {Object[].class};
Object[] objs1 = {hostName, port, null, env.getProperty (dermi.Context.PROTOCOL)};
Object[] objs = {objs1};
String className = "dermi.core.DermiConnection";
connection = (DermiConnection) Class.forName(className).getConstructor (cl).newInstance (objs);


The constructor's signature is:

public DermiConnection (Object ... args) throws
ConnectionException { }

Thanx in advance.

--

Carles.
 
This topic has 1 reply on 1 page.