A problem using java reflection api
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Vidula_Kulkarni
Posted On:   Sunday, November 11, 2001 09:01 PM


Iam using the reflection api to :

  1. Find out the constructors and the parameters of a particular class
  2. Create instances using them

I cannot create instances when the constructor parameters are primitive datatypes as the method of the constructor class:
Object o=xxx.new Instance(Object[])
takes an Object array as the parameter.
can someone help??
thanks

Re: A problem using java reflection api

Posted By:   Anonymous  
Posted On:   Sunday, November 11, 2001 10:24 PM

Hi,


Wrap the primitive data types into their corresponding objects.


Object Constructor::newInstance(object[]);
This is what the api docs say,

If the corresponding formal parameter has a primitive type, an unwrapping conversion is attempted to convert the object value to a value of the primitive type.
If this attempt fails, the creation throws an IllegalArgumentException.

If, after possible unwrapping, the parameter value cannot be converted to the corresponding formal parameter type
by a method invocation conversion, the creation throws an IllegalArgumentException.



~vivek
About | Sitemap | Contact