Issue
Is there an easy way in Java 8 to have String Constants match its value, instead of doing this repetitively?
public static final String PATIENTID = "PATIENTID";
public static final String CREATEDDATE = "CREATEDDATE";
public static final String PREFIX = "PREFIX";
public static final String FIRSTNAME = "FIRSTNAME";
public static final String MIDDLENAME = "MIDDLENAME";
Solution
You could use an enum:
public enum Field {
PATIENTID,
CREATEDDATE,
PREFIX,
FIRSTNAME,
MIDDLENAME;
}
and when you want to use one of your strings, you can use for example Field.PATIENTID.name()
, which will return the string "PATIENTID"
.
Answered By - khelwood
Answer Checked By - Timothy Miller (JavaFixing Admin)