dcsimg
In a String I've got the type of a class, in another one the value. I want to create an instance of the class with the value...
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Alexia_Schumacker
Posted On:   Tuesday, November 19, 2002 12:09 AM

Hi,



I've got two String :

String one "returnType.getName()" = type of a class (for example: java.sql.Timestamp)

String two = "22102002" the date



with this I create an instance :

instance = Class.forName(returnType.getName()).newInstance();

But my problem is to assign the String two to this instance...


Thank you for your help

Alexia

Re: In a String I've got the type of a class, in another one the value. I want to create an instance of the class with the value...

Posted By:   Lasse_Koskela  
Posted On:   Tuesday, November 19, 2002 03:26 AM

I guess you need to state the requirement that the given class must have a constructor accepting some specific parameter (in this case, a single String object), or a kind of setValue(String valueToSet) method.


Then you could locate the constructor/method using the java.lang.reflect API and invoke the constructor/method with the second String object.

About | Sitemap | Contact