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 class)?


  • From: xwang@xxxxxxxxxxxxxxxxx (Alvin Wang)
  • Subject: [Advanced-java] How to String->Class (not instance of Class class)?
  • Date: Wed, 13 Mar 2002 09:46:29 -0500

However, from your code, ridHome is an instance of Object, not an instance
of SpecialRequestIDHome. How can you convert danamically?


-----Original Message-----
From: advanced-java-admin@xxxxxxxxxxxxxxxxxxxxxx
[mailto:advanced-java-admin@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Pollard,
Jim
Sent: Tuesday, March 12, 2002 6:39 PM
To: 'xwang@xxxxxxxxxxxxxxxxx'; advanced-java@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [Advanced-java] How to String->Class (not instance of Class
class)?


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
>
_______________________________________________
Advanced-java mailing list
Advanced-java@xxxxxxxxxxxxxxxxxxxxxx
http://lists.xcf.berkeley.edu/mailman/listinfo/advanced-java