[3605] in java-interest
Dynamic Object Instantiation ....
daemon@ATHENA.MIT.EDU (Anselm Baird_smith)
Fri Nov 17 08:17:32 1995
Date: Fri, 17 Nov 1995 12:18:39 +0100
From: Anselm Baird_smith <Anselm.Baird_Smith@inria.fr>
To: neudeck.arthur@ch.swissbank.com
Cc: java-interest@java.sun.com, neudeca@ch.swissbank.com
In-Reply-To: <9511171042.AA16383@foxy.ch.swissbank.com>
Reply-To: Anselm Baird-Smith <Anselm.BairdSmith@inria.fr>
neudeck arthur writes:
> Hoi ....
>
> I've got a problem (what else ?? ;-)):
>
> I load a new class by a given name from a directory.
> Afterwards I instantiate a new Object that way:
> Object newObject = Class.forName("...")
>
> Everything works fine until the moment I try to call a method of this new
> object. I do have the problem, that the Class object does not provide the
> called method, e.g.:
> newObject.getOID();
>
> How can I instantiate the object with the right cast???
Try something like:
Persistent object = null ;
try {
object = (Persistent) Class.forName(cls).newInstance() ;
} catch (ClassNotFoundException e) {
} catch (InstantiationException e) {
} catch (IllegalAccessException e) {
}
if ( object == null ) {
throw new PersistentInitException ("Unable to make instance.") ;
}
You're probably missing the cast to (Persistent).
BTW: has anyone implement a dbm like package in Java ?
Anselm.
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com