Interface Generator

  • All Superinterfaces:
    AccessFlags

    public interface Generator
    extends AccessFlags
    Bytecode generator.

    Example (the sample method in the generated class does nothing):

       public GenClass generate(String className) throws Exception {
      
         Type objectType = new Type(Object.class);
         GenClass genClass = new GenClass(ACC_PUBLIC | ACC_FINAL, className, objectType);
       
         genClass.createDefaultConstructor();
       
         Type voidType = new Type(Void.TYPE);
         GenMethod method = genClass.createMethod(ACC_PUBLIC, voidType, "doNothing");
         CodeAttribute code = method.getCode();
         code.returnVoid();
      
         return genClass;
       }
     
    Author:
    Uwe Finke
    • Method Detail

      • generate

        GenClass generate​(String className)
                   throws Exception
        Generates bytecode.
        Parameters:
        className - name of the class
        Returns:
        GenClass containing the bytecode.
        Throws:
        Exception - any exception during bytecode generation