Enum exeeding the 65535 bytes limit of static initializer… what's best to do?

后端 未结 5 1654
囚心锁ツ
囚心锁ツ 2021-01-03 23:30

I\'ve started a rather large Enum of so called Descriptors that I\'ve wanted to use as a reference list in my model. But now I\'ve come across a compiler/VM

5条回答
  •  滥情空心
    2021-01-04 00:14

    You can try the typesafe enum pattern described by Joshua Bloch in the first edition of his book "Effective Java".

    The idea is to create a class with a private constructor. Inside this class you define static instances of any number you want to-just as in a Java enum.

    I don't know if there is a limit for the number of static members in the Java language, though.

提交回复
热议问题