This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: creating classes at runtime


This doesn't answer your overall question, but as far as what you're seeing with Class.forName(), I think the classes you're creating through load are created as byte-code arrays in memory and then loaded by an appropriate class loader. The "current" class loader probably doesn't know anything about this, so you get the exception. If you got a hold, somehow, of the right class loader, you could pass it to the three-argument Class.forName() method and that would work.

Dean

Robert Nikander wrote:
I'm looking for a way to create instances from classes defined in .scm files that are written at runtime.
Is there a recommended way to do this? I'm guessing that (load file) is the way, but it's behavior is surprising me.


I'm calling (load "foo.scm") and I thought that any define-simple-class in foo.scm would be available via Class.forName. But Class.forName("FooClass") throws ClassNotFoundException. I can, however, create a FooClass with (make <FooClass>). I also notice that if I rewrite and reload foo.scm, the (make <FooClass>) will create an instance of the new class. How does this work? I thought Java couldn't redefine a class once it was loaded?

Right now, I'm thinking I can instantiate the dynamically created class like this:

(write-scm-file file-name)
(load file-name)
(eval `(make ,class-name))

Is there a better way?

Rob


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]