// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtNewMethod;

public class TestJA {
    public static void main(String[] args) throws Exception  {
        ClassPool pool = ClassPool.getDefault();
        CtClass cc = pool.makeClass("fun.Foobar");
        cc.addInterface(pool.get("fun.Isome"));
        cc.addMethod(CtNewMethod.make("public void dosomething() { System.out.println(\"I am foobar\"); }", cc));
        Class<Isome> clz = cc.toClass();
        Isome o = clz.newInstance();
        o.dosomething();
    }
}

interface Isome {
    public void dosomething();
}
