javajavapoet

How to add static section in to java class in javapoet


Is there a anyway to add static code block into java class using javapoet library

static {
        // whatever code is needed for initialization goes here
    }

Solution

  • Use TypeSpec.Builder::addStaticBlock. See this test case for an example.