I’ve been finding several bugs in my project that are due to enums being null, instead of one of the enumerated values. Is there a way to guarantee that a variable of this type will always be initialized with one of the enumerated values, and never be null?
Share
No. Enums are always reference types, and
nullis a valid value for any reference type. You can always write:and if you have an instance or static variable which isn’t initialized explicitly, it will always default to null.