I have a unit test where I have statically defined a quite large byte array (over 8000 bytes) as the byte data of a file I don't want to read every time I run my unit test.
private static final byte[] FILE_DATA = new byte[] {
12,-2,123,................
}
This compiles fine within Eclipse, but when compiling via Ant script I get the following error:
[javac] C:\workspace\CCUnitTest\src\UnitTest.java:72: code too large
[javac] private static final byte[] FILE_DATA = new byte[] {
[javac] ^
Any ideas why and how I can avoid this?
Answer: Shimi's answer did the trick. I moved the byte array out to a separate class and it compiled fine. Thanks!
So, refactoring the erring method into several smaller methods will fix the problem for us. In the case of array initializations, we can either split the arrays or load from a file. We can also use static initializers. Even when we're using code generators, we can still refactor the code.
If the brackets don't all match up, the result is a compile time error. The fix to this compile error is to add a leading round bracket after the println to make the error go away: int x = 10; System.
A method is a block of code which only runs when it is called. You can pass data, known as parameters, into a method. Methods are used to perform certain actions, and they are also known as functions.
Methods in Java are restricted to 64k in the byte code. Static initializations are done in a single method (see link)
You may try to load the array data from a file.
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