anonymous / else.java
Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

else

View else.java
1 2 3 4 5 6 7 8 9 10 11
String timeZone;
try {
timeZone = getParam("timezone");
if (null == timeZone) {
throw new Exception();
}
} catch (final Exception e) {
return "US/Eastern";
}
 
return timeZone;

Why not:

String timeZone = getParam("timezone");
return (timeZone ? timeZone : "US/Eastern");

?

because timeZone isn't a boolean
this isn't C, unfortunately

Best way with java 8 optional
String timeZone = getParam("timezone").orElse("US/Eastern");

String timeZone = getParam("timezone");
return timeZone == null ? "US/Eastern" : timeZone;

oh yeah. Verbosity in a language makes it Enterprise Ready

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.