wiki:UsingClassWriter

Version 2 (modified by mevenson, 4 years ago) (diff)

--

Dynamically Creating Java Interfaces

As of r13071, one can use the classwriter in the JVM package to dynamically create a Java interface.

(let* ((class-name (jvm::make-jvm-class-name "org/not/Foo"))
       (class (jvm::make-class-file class-name +java-object+ '(:public :interface)))
       (method (jvm::make-jvm-method "callback" :int '(:int) :flags
                                '(:public :abstract))))
  (jvm::class-add-method class method)
  (jvm::finalize-class-file class)
  (with-open-file (s #p"Foo.class" :direction :output 
                     :if-exists :supersede :element-type '(unsigned-byte 8))
    (jvm::write-class-file class s)))