Note that there are some explanatory texts on larger screens.

plurals
  1. POSize of Initialisation string in java
    primarykey
    data
    text
    <p>Apparently there is a limit to the size of an initialisation string in javac. Can anyone help me in identifying what the maximum limit is please?</p> <p>Thank you</p> <p><strong>edit:</strong></p> <p>We are building an initialisation string which will look something like this "{1,2,3,4,5,6,7,8......}" but with 10,000 numbers ideally. When we do this for a 1000 it works, 10,000 throws an error saying code too large for try statement. </p> <p>To produce this we are using a stringbuilder and looping over an array appending the values. Apparently it is a limitation in javac. We have been told that we could rebuild the array in the method we are invoking if we pass it in small chunks. This however is not possible because we dont have control over the user method we are invoking.</p> <p>I would like to post code but can't because this is a project for University. I am not looking for code solutions just some help in understanding what the actual problem here is. </p> <p>Its the for loop which is the offender </p> <pre><code> Object o = new Object() { public String toString() { StringBuilder s = new StringBuilder(); int length = MainInterfaceProcessor.this.valuesFromData.length; Object[] arrayToProcess = MainInterfaceProcessor.this.valuesFromData; if(length == 0) { //throw exception to do } else if(length == 1) { s.append("{" + Integer.toString((Integer)arrayToProcess[0])+"}"); } else { s.append("{" + Integer.toString((Integer)arrayToProcess[0])+","); //opening statement for(int i = 1; i &lt; length; i++) { if(i == (length - 1)) { //last element in the array so dont add comma at the end s.append(getArrayItemAsString(arrayToProcess, i)+"}"); break; } //append each array value at position i, followed //by a comma to seperate the values s.append(getArrayItemAsString(arrayToProcess, i)+ ","); } } return s.toString(); } }; try { Object result = method.invoke(obj, new Object[] { o }); </code></pre> <p>} </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload