wiki:UsingClassWriter

Version 1 (modified by Mark Evenson, 11 years ago) (diff)

Creating interfaces

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