-
Notifications
You must be signed in to change notification settings - Fork 2
FAQ
Run with the -Dorg.cojen.maker.ClassMaker.DEBUG=true
command line option. It prints a message (to standard out) for every class being generated, and it writes a class file to the temp directory.
ClassMaker writing to /tmp/ClassMaker/org.cojen.maker.ClassMaker-1(0).class
If the class isn't abstract but it still has abstract methods, the message also reports which methods still need to be implemented.
ClassMaker writing to /tmp/ClassMaker/Test-1(0).class; unimplemented methods: [int applyAsInt(long)]
The debug option also disables this check: java.lang.IllegalStateException: Accessing an unassigned variable
. In doing so, an unverifiable class is generated, and a class file is written which can be inspected with a disassembler or decompiler.
If function "a" calls function "b" which then calls function "a", then both of the functions must be declared before they are defined. Otherwise an IllegalStateException
is thrown because the dependent function cannot be found.
// Declare both functions before defining any code.
MethodMaker mma = cm.addMethod(int.class, "a", int.class).static_();
MethodMaker mmb = cm.addMethod(int.class, "b", int.class).static_();
// Define code for "a", which invokes "b".
...
mma.invoke("b", ...);
// Define code for "b", which invokes "a".
...
mmb.invoke("a", ...);
Note that in this example, the methods are declared static_
up front. This ensures that the correct method invocation instructions are generated.