Maximum size of a method in java?

后端 未结 3 592
感动是毒
感动是毒 2020-11-27 19:30

I come to know that the maximum size of a method in java is 64k. And if it exceeds, we\'ll get a compiler warning like \"Code too large to compile\". So can we call this a

3条回答
  •  無奈伤痛
    2020-11-27 20:08

    In my experience the 64KB limit is only a problem for generated code. esp. when intiialising large arrays (which is done in code)

    In well structured code, each method is a manageable length and is much smaller than this limit. Large pieces of data, to be loaded into arrays, can be read from a non Java files like a text or binary file.

    EDIT:

    It is worth nothing that the JIT won't compile methods larger than 8 K. This means the code runs slower and can impact the GC times (as it is less efficient to search the call stack of a thread with methods which are not compiled esp big ones)

    If possible you want to limit your methods to 8 K rather than 64 K.

提交回复
热议问题