Hi I am trying to initialize 4 string arrays of length 10,100,1000,10000 and these arrays are like
array1={"0","1",..."9"}
array2={"00","01",..."99"}
array3={"000","001",..."999"}
array4={"0000","0001",..."9999"}
But I am getting the error of The code for the static initializer is exceeding the 65535 bytes limit
how can I initialize my arrays?
Also note that loading it from file is not an option for me :(
Constant array in are initialized in java bytecode by loading each value from the constant pool and assigning it to the corresponding array index. This takes several bytes of code per array element. The size of a jvm method is limited to 65535 bytes since its length is stored in the class file using a 16 bit number.
In the case where the values can not be easily calculated in a loop, you could break the initialization into separate static functions:
static {
array1 = getValuesForArray1();
...
}
private static String[] getValuesForArray1() {
...
}
If there is a pattern to the initialization values its of course better to calculate the values on the fly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With