G
Glenn Robinson
Joona said:Glenn Robinson <[email protected]> scribbled the following
Michael Borgwardt wrote:Glenn Robinson wrote:
I create a new class object at runtime using:
Class dmClass = Class.forName(dmClassName);
[]
How can I use dmClass as the cast type in a statement?
You cannot, that's impossible.
What are you trying to achieve with it anyway?I have:
interface DataManager
class SasDMImp which implements DataManagerI do the following:String dmClassName = "SasDMImp";
Class dmClass = Class.forName(dmClassName);I now want to use the SasDMImp class to cast a new object and this is the
part I'm having trouble with.If I hard code the class name I use:SasDMImp dm = (SasDMImp) Naming.lookup("rmi://" +host + registry);I want to replace the hard coded SasDMImp with dmClass but I get the
Invalid Cast type when I do this.Hope this helps.
This is a well-known situation. Our application uses this form of code
about a hundred times.
My answer to your problem is: Forget about casting to SasDMImp. Cast to
DataManager instead, as it's a known interface, and code that uses your
data manager shouldn't have to care about whether you have a SadDMImp or
some other implementation. If it does, you have a design problem.
Thanks, this is what I wanted. I cast using the interface DataManager and
all worked just fine.
Appreciate you comments and help.
Glenn