From: Ken A. <kan...@bb...> - 2003-01-07 14:50:18
|
At 10:00 PM 1/6/2003, david may wrote: >I found this today, and it seems usefull. >are there any gotchas to this method oc creating >new class in jscheme? In addition to what Tim said, you need to be a little careful when using multiple class loaders. Loaders have a parent link and when loading a class they are supposed to ask the parent to load the class first, if it can. If it can't the loader will try loading it. Unfortunately, a class loaded by the parent of a class loader can't see a class loaded by the class loader. I use dynamic class loading, for example the following code will add all the jar files in the lib/ directory to the class path: (load "using/run.scm") (load "elf/classpath.scm") (for-each (lambda (u) (.addURL (Import.getClassLoader) (url u))) (files* (File. "lib") isJarFile)) I even sometimes smash the system class loader. I think the right solution is to have your main create at class loader and then run your application through it, as Chiba's tutorial shows. See build/SchemeLite.java for example. I'm having a problem with the Bean Scripting Framework related to this and may change how JScheme starts. BTW, i have a class loader that will let you reload a Java class. This will let you test a Java class through JScheme and let you recompile it without leaving JScheme. >Sometimes you want to make a subclass just to >override the paint method. > >the jar file is here.. >http://www.csg.is.titech.ac.jp/~chiba/javassist/ > >------------ a simple test ----------- >(import "javassist.*") >(define pool (javassist.ClassPool.getDefault)) >(define cc (.makeClass pool "Silly")) >(define m (CtNewMethod.make > "public int silly(int dx) { return 2+dx; }" cc)) >(.addMethod cc m) > >(define cloader (Loader. pool)) >(define anewclass (.loadClass cloader "Silly")) >(define ss1 (.newInstance anewclass)) > >(.silly ss 1) > > >------------------------------------------------------- >This sf.net email is sponsored by:ThinkGeek >Welcome to geek heaven. >http://thinkgeek.com/sf >_______________________________________________ >Jscheme-user mailing list >Jsc...@li... >https://lists.sourceforge.net/lists/listinfo/jscheme-user |