“Code too large” compilation error in Java

后端 未结 13 1196
半阙折子戏
半阙折子戏 2020-11-22 14:33

Is there any maximum size for code in Java? I wrote a function with more than 10,000 lines. Actually, each line assigns a value to an array variable.

arts_b         


        
相关标签:
13条回答
  • 2020-11-22 15:00

    Try to refactor your code. There is limit on the size of method in Java.

    0 讨论(0)
  • 2020-11-22 15:00

    As there is a size limit for methods and you don't want to redesign your code as this moment, may be you can split the array into 4-5 parts and then put them into different methods. At the time of reading the array, call all the methods in a series. You may maintain a counter as well to know how many indexes you have parsed.

    0 讨论(0)
  • 2020-11-22 15:04

    You can add another method to create space for your code for additional data space, you might have a method that is taking a large amount of data space. Try dividing your methods because I had the same issue and and fix it by creating another an additional method for the same data in my java Android code, The issue was gone after I did that.

    0 讨论(0)
  • 2020-11-22 15:06

    This seems a bit like madness. Can you not initialize the array by reading the values from a text file, or some other data source?

    0 讨论(0)
  • 2020-11-22 15:08

    this is due to all code in single methods solution :create more some small methods then this error will be gone

    0 讨论(0)
  • 2020-11-22 15:10

    According to the Java Virtual Machine specification, the code of a method must not be bigger than 65536 bytes:

    The value of the code_length item gives the number of bytes in the code array for this method.

    The value of code_length must be greater than zero (as the code array must not be empty) and less than 65536.

    code_length defines the size of the code[] attribute which contains the actual bytecode of a method:

    The code array gives the actual bytes of Java Virtual Machine code that implement the method.

    0 讨论(0)
提交回复
热议问题