Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Advanced-java] How to String->Class (not instance of Class c lass)?


  • From: Pollard@xxxxxxxxx (Pollard, Jim)
  • Subject: [Advanced-java] How to String->Class (not instance of Class c lass)?
  • Date: Tue, 12 Mar 2002 17:38:35 -0600

i'm not sure what you were doing with c.class (the Class object has no
public properties), but i think what you are missing is a call to
newInstance() something like this :

String className = getClassName(); //get class name from config file. for
example "SpecialRequestIDHome"
Class c = Class.forName(className);
Object d = c.newInstance();
Object ridHome = PortableRemoteObject.narrow(ref, d.class);

> -----Original Message-----
> From: Alvin Wang [mailto:xwang@xxxxxxxxxxxxxxxxx]
> Sent: Tuesday, March 12, 2002 5:30 PM
> To: advanced-java@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [Advanced-java] How to String->Class (not instance of Class
> class)?
> Importance: High
> 
> 
> Hi! I have a question regarding reflection. My current code 
> is like this:
> 
> RequestIDHome ridHome = 
> (RequestIDHome)PortableRemoteObject.narrow(ref,
> RequestIDHome.class);
> 
> I am trying to make it more dynamic on the class I am going 
> to use, that
> means to replace RequestIDHome with a "Class variable". For 
> example, in code
> I need to dynamically create a class from a String 
> "SpecialRequestIDHome"
> got from config file. If I use
> 
> String className = getClassName(); //get class name from 
> config file. for
> example "SpecialRequestIDHome"
> Class c = Class.forName(className);
> 
> I will get a instance of Class class, not the Class 
> SpecialRequestIDHome.
> Aparently, I cannot do this as I want:
> 
> c ridHome = (c)PortableRemoteObject.narrow(ref, c.class);
> 
> All in all, all I want to do is to get the class (not 
> instance of Class
> class, not the instance of the class) from a String. (how to 
> convert String
> "SpecialRequestIDHome" to a "class vaiable" representing class
> SpecialRequestIDHome? Is there this kind of variable in Java?) Or any
> workaround?
> 
> Can any guru help? thanks!
> 
> _______________________________________________
> Advanced-java mailing list
> Advanced-java@xxxxxxxxxxxxxxxxxxxxxx
> http://lists.xcf.berkeley.edu/mailman/listinfo/advanced-java
>