+ 2

What is "enum" used for?

Java

15th Jul 2021, 1:55 AM
Vuyolwethu Mableka
Vuyolwethu Mableka - avatar
2 Antworten
+ 2
enums are used when a variable (especially a method parameter) can only take one out of a small set of possible values. Enums improve both likelihood of correctness and readability without writing a lot of boilerplate. If you use enums instead of integers or data-type, you increase compile-time checking and avoid errors from passing in invalid constants
15th Jul 2021, 2:16 AM
Rellot's screwdriver
Rellot's screwdriver - avatar
0
readable, easy-to-remember markers for various status, e.g. enum Suit {Heart, Diamond, Club, Spade}; is better than numeric codes. Suit.Diamond take less memory than "Diamond" String
15th Jul 2021, 6:38 AM
zemiak