Friday, 15 February 2013

performance - What's the limit to the number of members you can have in a java enum? -


Assuming you have a hypothetical enum in Java (for display purposes like this), this code is not Seriously expecting to use):

  Example example {FIRST, SECOND, THIRD, ... LAST; }  

The compiler prevents you before what the maximum number of members can be?

Secondly, there is a difference in any runtime when your code says with a NAM, there are 10 members in opposition to 100 or 1,000 (except for a clear memory overhead required to store only the larger category) ?

The best way to answer this type of question is to try to generate Java files Start with a little Python script for:

  n = input () print "class A {public static zero main (string [] a) {} enum B {" print ',' ("C% d" in the range (n) x) Print '}}'  

Now try with 1,10,100,1000 ... works fine, then Balm:

Agava: Code too large C0, C1, C2, C3, C4, C5, C6, C7, C8, C9, C10, C11, C12 , C3, C14, C15, C16, C17, C18, C19, C20, C21, C22, ...

It seems that I have some kind of It is not certain that it is a documented limitation, if it is dependent on the specific version of the compiler, or if it hits the internal border Stm dependent limit but the limit for me around 3000 and it is related to the source code size. You may be able to write your own compiler to bypass this limit.


No comments:

Post a Comment