On 16/10/2009, JS <jshell...@gmail.com> wrote: > How would I set the serialVersionUID using BCEL? I'm using BCEL's > ClassLoader, overriding modifyClass. I have it adding the Serializable > interface successfully, but I also need to set the serialVersionUID > for the class. How would I do so?
Hi, You want to create a FieldGen with the UID you want and add it to the ClassGen, e.g.: ClassGen classGen = new ClassGen( clazz ); // create a FieldGen for 'private static final int serialVersionUID' FieldGen fieldGen = new FieldGen( Constants.ACC_PRIVATE | Constants.ACC_FINAL | Constants.ACC_STATIC, Type.INT, "serialVersionUID", classGen.getConstantPool() ); // set an initial value fieldGen.setInitValue( mySerialVersionUID ); // add it to the class classGen.addField( fieldGen.getField() ); JavaClass modifiedClass = classGen.getJavaClass(); I hope that helps. (I haven't actually compiled and tested that code.) Kind regards, Matthew --------------------------------------------------------------------- To unsubscribe, e-mail: bcel-user-unsubscr...@jakarta.apache.org For additional commands, e-mail: bcel-user-h...@jakarta.apache.org