Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The language specification itself doesn't have a limit. Yet, there are many limitations that classfile has that bound the number of enums, with the upper bound being aruond 65,536 (2^16) enums:</p> <p><strong>Number of Fields</strong> The <a href="http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html#74353" rel="noreferrer">JVMS 4.1</a> specifies that <code>ClassFile</code> may have up to 65,536 (2^16) fields. Enums get stored in the classfile as static field, so the maximum number of enum values and enum member fields is 65,536.</p> <p><strong>Constant Pool</strong> The JVMS also specifies that the Constant Pool may have up to 65,536. Constant Pools store all String literals, type literals, supertype, super interfaces types, method signatures, method names, <em>AND</em> enum value names. So there must be fewer than 2^16 enum values, since the names strings need to share that Constant Pool limit.</p> <p><strong>Static Method Initialization</strong> The maximum limit for a method is 65,535 bytes (in bytecode). So the static initializer for the Enum has to be smaller than 64Kb. While the compiler may split it into different methods (Look at <a href="http://bugs.sun.com/view_bug.do?bug_id=4262078" rel="noreferrer">Bug ID: 4262078</a>) to distribute the initializations into small blocks, the compiler doesn't do that currently.</p> <p>Long story short, there is no easy answer, and the answer depends not only on the number of enum values there are, but also the number of methods, interfaces, and fields the enums have!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload