A class having 2500 static field or instance variable along with getter and setter and some code . total line of code is more than 20000, and this class is auto generated, its not getting compiled, compilation error is " code too large" , how to fix it and what is max line of code could be in java file.
Asked
Active
Viewed 144 times
3
-
The static block, which initialises all static fields, is a method which is limited to 64K of code. The solution is to not put so many static fields in 1 class. You can use multiple interfaces instead if you have to. – Peter Lawrey Mar 14 '16 at 17:38
1 Answers
0
The limit is not related to total lines of code but to size of methods - one method may only be at most 64KB of bytecode. Note that all static initializers (including variables' default values) are compiled as a single method.
If the problem is in static initializer, move some code from it into methods (so that the total bytecode gets separated into multiple methods, each small enough to compile). If the problem is in an ordinary method being too large, separate the code into multiple methods. Most likely this will involve modifying the code generator, so hopefully you are able to do this (if it's some commonly used tool, it would be helpful if you specified what tool you use so the advice can be specific to the tool).

Jiri Tousek
- 12,211
- 5
- 29
- 43