> Does anyone has experience in passing a class as a parameter in java?
> I want to do something like call a method with as parameter a class name and
> then create instances of that class in that method. Is this possible?

try this:
public Object makeInstance(String sClassName)
{
        Class rClass = Class.forName(sClassName);
        Object rObject = rClass.newInstance();
   ... do what you want with the object ...
        return(rObject);
}
I've not included any checks for possible exceptions like 'ClassNotFound',
but the idea is sound (and I've tried it).

But the best is to read the javadoc documentation for java.lang.Class

Cheers, Craig

------
"If God had intended Man to Watch TV, He would have given him Rabbit
 Ears."

======================================================================
Craig Taverner               ------======       Email:[EMAIL PROTECTED]
ComOpt AB                   ------========        Tel:   +46-42-212580
Michael Löfmans Gata 6     ------==========       Fax:   +46-42-210585
SE-254 38 Helsingborg       ------========       Cell:  +46-708-212598
Sweden                       ------======        http://www.comopt.com
======================================================================

Reply via email to