Ok now I understand that its not possible to use new, like it isn't possible to call the methods directory - it all has to be done with newInstance and reflection; due to the need to compile first.
I've gone over the example at: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/repast-jellytag/repast-je lly-taglibrary/src/org/apache/commons/jelly/tags/bcel/ClassExtender.java ?rev=1.1&content-type=text/vnd.viewcvs-markup The class loader stuff seems pretty complicated there, and I don't understand a word of it. However I found the following to work: try { Class Revision = Class.forName(className); Object revision = Revision.newInstance(); revision.setDescription("Mark"); System.out.println(revision.getDescription()); } catch(Exception e) { e.printStackTrace(); } Is that ok, is there a reason why I should be doing it as in the linked example? Mark -----Original Message----- From: Mark Proctor (mproctor) Sent: 01 April 2003 17:01 To: BCEL Users List; [EMAIL PROTECTED] Subject: RE: Generating method Code for setters Could a variation on Class.forName be used - like with jdbc driver loading - to then allow normal instance creation with "new". If the file has to be in the classpath, could you "dump" the class and then use Class.forName? Mark -----Original Message----- From: Mark R. Diggory [mailto:[EMAIL PROTECTED] Sent: 01 April 2003 15:34 To: Mark Proctor (mproctor); [EMAIL PROTECTED] Subject: Re: Generating method Code for setters Mark Proctor (mproctor) wrote: > Mark, > > I'm having to read up on classloaders and security - as it still doesn't > mean much to me :( - I don't understand why you have to do > myclass.newInstance - how can I get it to operate like a normal class so > I can just do MyClass myclass = new MyClass(). > I think that may be tough to do because using "new" really requires that class to be present at "compile time", while the BCEL based class you've generated is only available during the "runtime" of JVM instance your created it in. Thats why you need to use newInstance at that point. Now, if your creating the BCEL class and then saving it to a class file for future use in another "JVM" instance, I think you can use it with "new" because it really is just like any other class. I could be incorrect on this, I will cross post tot he list to get some critique. -MRD > Do you use IRC or ICQ? > Nope, sorry, I pretty much stick to email. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
