tags:

views:

102

answers:

1

I would like to initialize static fields in the static initializer of a class; and this in bcel. I haven't found a way to do so however... any hints?

I need something like:

// Field descriptor #8 [I private static int[] a;

static {}; 0 bipush 10 2 multianewarray int[] [9] 6 putstatic Output.a : int[] [11] 9 return

I however only seem to be able to generate (with MethodGen) things like:

public static void {}(); 0 bipush 10 2 multianewarray int[] [9] 6 putstatic Output.a : int[] [11] 9 return

Which is of course not the same...

Thanks!

+1  A: 

Just found it myself.

 MethodGen method = new MethodGen(Constants.ACC_STATIC,
   Type.VOID,
   new Type[] { }, new String[] { }, "<clinit>",
   cg.getClassName(), il, cg.getConstantPool());

clinit seems to be the class initializer ...