Is there a way to implement an inline switch statement in java?
Right now, i'm using the following:
private static String BaseURL = (lifeCycle == LifeCycle.Production)
? prodUrl
: ( (lifeCycle == LifeCycle.Development)
? devUrl
: ( (lifeCycle == LifeCycle.LocalDevelopment)
? localDevUrl
: null
)
);
I would much prefer it if I could do something like:
private static String BaseURL = switch (lifeCycle) {
case Production: return prodUrl;
case Development: return devUrl;
case LocalDevelopment: return localDevUrl;
}
I do know you could achieve this by moving the
BaseURLvariable into a functionGetBaseURLwhere the switch occurs (see below), however I'm more so just curious if this feature even exists in Java.
static String GetBaseURL() {
switch(lifeCycle) {
case Production: return prodUrl;
case Development: return devUrl;
case LocalDevelopment: return localDevUrl;
}
return null;
}
I'm transitioning from Swift, and in Swift I know you could do this:
private static var BaseURL:String {
switch (API.LifeCycle) {
case .Production:
return prodUrl
case .Development:
return devUrl
case .LocalDevelopment:
return localDevUrl
}
}
switchstatement? It would be much cleaner with aMap