Skip to content
Advertisement

Can Java enum class set default value

Mycode is

JavaScript

which I want

JavaScript

can I hava a default value which is not in it, can it be set as a default value? because I have a type is “%”, but enum is not support %, so I want a default value to solve it

Advertisement

Answer

The default for one who holds a reference to an enum without setting a value would be null (either automatically in case of a class field, or set by the user explicitly).

Unfortunately you cannot override the method valueOf for your own enum, as it is static.

But you can still create your methods:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement