Yup I figured that out ...
but how do I do a typecast when I have the class name in a String 
variable during runtime. (I do NOT know the class name to typecast).

On Thu, 4 Nov 1999, Nathan Meyers wrote:

> Nathan Meyers wrote:
> > SABYASACHI S GUPTA wrote:
> > > 
> > > public class saby {
> > > 
> > >         public static void main(String args[])
> > >         {
> > > 
> > >                 String s = "myclass";
> > >                 Class c = new Class();
> > >                 try {
> > > 
> > >                          c  = Class.forName(s);
> > > 
> > >                 Object b = c.newInstance();
> > >                 b.method();   // I know this is an error..so what to do?
> > 
> > You need to use the reflection API. Use b.getMethod() to get a handle
> > (of type Method) for the method, then use Method.invoke() to run that
> > method.
> 
> Please ignore previous dumb advice :-). You would use the Reflection
> API on c (the Class instance). You need a typecast to use b (the myclass
> instance).
> 
> Nathan
> 



----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to