Are blank lines allowed as members of an enum in Java

I have a problem with some outdated code. The ticket asks me to write a script to verify the validity of the process; however, I keep getting this exception when the script runs:

 java.lang.IllegalArgumentException: No enum const class edu.cmu.s3.common.enums.RegistrationStatus.;

For the record, the database used is the old legacy Ingres system, so null values โ€‹โ€‹appear as empty strings - pretty pretty, I have to add.

In any case, it seems that whenever an empty string is encountered, it does not work when creating enums. I checked the listing, although it contains this member:

BLANK("", "Blank")

This would make me think that an empty string is indeed a valid argument, but it seems like it is not.

CAN enums use empty strings as arguments, or will I need to update older code than I originally expected?

thanks for the help

+3
source share
2 answers

An empty string is a valid argument for the enum constructor, but it is not a valid enumeration name.

Each enum variable name must be a valid Java identifier.

+9
source

If you use Enum.valueOf(String)to parse Stringsfrom your database into Enums, then your problem is that they are valueOfdisconnected from the name Enum, i.e. BLANK.

This will work for you: Enum.valueOf( "BLANK" )

But not: Enum.valueOf( "" )

Enums , Enum, .

+1

All Articles