Search code examples
jcodemodel

How to generate static initialization block with jcodeModel


I need to generate something like this with jcodemodel

package com.example;

    public class Main {

    static int a;

    static {
        a = 5;
    }

    public static void main (String[] args) {

    }

}

Google did not help. There is a class JBlock but there is nothing about initialization blocks.


Solution

  • need to call JDefinedClass.init() which returns JBlock