Maximum number of enum elements in Java

2019-01-11 22:24发布

What is the maximum number of elements allowed in an enum in Java?

I wanted to find out the maximum number of cases in a switch statement. Since the largest primitive type allowed in switch is int, we have cases from -2,147,483,648 to 2,147,483,647 and one default case. However enums are also allowed... so the question..

7条回答
Melony?
2楼-- · 2019-01-11 23:04

There is no maximum number per se for any practical purposes. If you need to define thousands of enums in one class you need to rewrite your program.

查看更多
登录 后发表回答