I have a class containing a large number of constants created as such:
public class Constants extends SomeBaseClass {
When the number of constants generated is very large, this leads to a static initializer that is greater than the upper limit for the size of the Java method (i.e.> 64 kB), which leads to a compiler error. One solution is to create several โblock initialization methodsโ for blocks that can be guaranteed to create less than 64 KB of byte code, so that they fit into the method:
public class Constants extends SomeBaseClass { public static XXX KEY1; public static XXX KEY2; public static XXX KEY3;
The disadvantage of this is that I can no longer declare constants as final
, because now they are no longer initialized directly in the static initializer.
My question is, how can I get around this / JVM compiler limitation in such a way that I can still generate static final
constants?
source share