- don't set default values, let it fail with an NPE if not taken correctly care of.
- if a default value is set, the mistake of careless will be spotted very much later (e.g. when the data is already persisted).
- if no default value is set (in this case it makes sense not set ...) an NPE is likely be thrown which might be spotted much earlier.
- this is good as bugs/bad data are detected (prevented in the end) earlier, too.
public UserContact () {
// Default is not user's own contact
this.contactOwnContact = Boolean.FALSE;
-
- // Unknown gender
- this.contactGender = Gender.UNKNOWN;
}
/**
*/
public enum Gender implements Serializable {
- /**
- * Unknown enum
- */
- UNKNOWN('U', "GENDER_UNKNOWN"), //NOI18N
-
/**
* Male enum
*/
// Walk through all genders
for (final Gender gender : Gender.values()) {
- // Is it not UNKNOWN
- if (!gender.equals(Gender.UNKNOWN)) {
- // Add it
- boolean added = list.add(gender);
-
- // Has it been added?
- assert (added) : MessageFormat.format("gender {0} not added.", gender); //NOI18N
- }
+ // Add it and check if it has been added
+ assert (list.add(gender)) : MessageFormat.format("gender {0} not added.", gender); //NOI18N
}
// Return it