0 Replies Latest reply on May 25, 2006 11:17 AM by Chang Zhou

    Why an abstract class generated?

    Chang Zhou Newbie

      I try to create a class BasicType
      public class BasicType implements java.io.Serializable{
      String _ISBN;

      public java.lang.String getISBN();
      public void setISBN(java.lang.String);
      public BasicType();
      }

      But I always get an abstract class, and the interface Serializable is not correct.
      C:\>javap BasicType
      Compiled from "BasicType.java"
      public abstract class BasicType extends java.lang.Object implements java.io.Serializable{
      public java.lang.String getISBN();
      public void setISBN(java.lang.String);
      public BasicType();
      }

      Anybody know why?

      Here are my codes:
      public class ClassGenerateSample extends ClassLoader{

      /**
      * @param args
      */
      public static void main(String[] args) {
      // TODO Auto-generated method stub
      try {
      ClassPool pool = ClassPool.getDefault();
      pool.importPackage("java.io.Serializable");

      CtClass cls = pool.makeClass("BasicType");
      //CtClass cls = pool.makeClass("FrameType");
      //cls.setName("BasicType");
      cls.addInterface(pool.get("java.io.Serializable"));

      CtField cfld = CtField.make("private java.lang.String _ISBN;", cls);
      cls.addField(cfld);

      CtMethod m = CtNewMethod.make("public java.lang.String getISBN();", cls);
      cls.addMethod(m);
      m.setBody("return _ISBN;");
      CtMethod m1 = CtNewMethod.make("public void setISBN(java.lang.String isbn);", cls);
      cls.addMethod(m1);
      m1.setBody(" _ISBN = $1;");

      cls.writeFile("c:\\");
      }
      catch (CannotCompileException e) {
      System.err.println("Cannot Compile Exception error");
      }
      catch (NotFoundException e) {
      System.err.println("Not Found Exception error");
      }
      catch (IOException e) {
      System.err.println("IO Exception error");
      }
      }
      }