I have a data class with some fields of enum type and some are just Strings. I need to create an object with just one String field and thus not include enum fields. How should I declare enum fields in my data class so that they will have an empty default value?
Vitali Plagov
01/21/2020, 9:10 AM
I can’t assign a certain enum value to this field to be its default.
I know that I can make this field nullable. But, maybe there’s a better solution than
null
?
z
Zach Klippenstein (he/him) [MOD]
01/21/2020, 9:26 AM
It’s pretty idiomatic to use a nullable type to indicate that a value may not be present, I would just make them nullable.
Even if you have the option of adding another enum value that represents “no value”, the advantage of using a nullable type instead is that you get nice syntactic sugar for dealing with the lack of a value (eg.