public byte[] toBytecode() {
// TODO: throw illegal state exception if the class file is modified after writing
if (bytecode == null) {
try {
ByteArrayDataOutputStream out = new ByteArrayDataOutputStream();
write(out);
bytecode = out.getBytes();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return bytecode;