“Code too large” compilation error in Java

后端 未结 13 1440
半阙折子戏
半阙折子戏 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 14:59

    As mentioned in other answers there is a 64KB of bytecode limit for a method (at least in Sun's java compiler)

    Too me it would make more sense to break that method up into more methods - each assigning certain related stuff to the array (might make more sense to use a ArrayList to do this)

    for example:

    public void addArrayItems()
    {
      addSculptureItems(list);
      ...
    }
    
    public void addSculptureItems(ArrayList list)
    {
      list.add("sculptures");
      list.add("stonesculpture");
    }
    

    Alternatively you could load the items from a static resource if they are fixed like from a properties file

提交回复
热议问题