import org.apache.bcel.Const;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.ConstantPoolGen;
import org.apache.bcel.generic.InstructionList;
import org.apache.bcel.generic.MethodGen;
import org.apache.bcel.generic.Type;
public class BCELExample {
public static void main(String[] args) {
ConstantPoolGen constantPoolGen = classGen.getConstantPool();
int stringIndex = constantPoolGen.addString("Hello, BCEL!");
InstructionList instructionList = new InstructionList();
instructionList.append(new org.apache.bcel.generic.GETSTATIC(constantPoolGen.addFieldref("java.lang.System", "out", "Ljava/io/PrintStream;")));
instructionList.append(new org.apache.bcel.generic.LDC(stringIndex));
instructionList.append(new org.apache.bcel.generic.INVOKEVIRTUAL(constantPoolGen.addMethodref("java.io.PrintStream", "println", "(Ljava/lang/String;)V")));
instructionList.append(new org.apache.bcel.generic.RETURN());
methodGen.setMaxStack();
methodGen.setMaxLocals();
classGen.addMethod(methodGen.getMethod());
classGen.getJavaClass().dump("HelloWorld.class");
}
}