Is there any difference in declaring static strings versus Enums. example:
public static final String SUNDAY = "SUNDAY";
or
enum WEEK
{
SUNDAY;
}
Is there any difference in declaring static strings versus Enums. example:
public static final String SUNDAY = "SUNDAY";
or
enum WEEK
{
SUNDAY;
}
If your app deals with days of the week as a type, then using an enum maintains type safety, preventing you from making mistakes when handling days of the week. If you make it a string, your date class could just as easily print "Today is JOE SCHMOE, July 23rd."
Using an enum scopes the name. You have to write WEEK.SUNDAY
instead of just SUNDAY
, which will make your code cleaner. Also before 1.7, you could not use strings in switch statements.