Is there a way in Java 8 to simultaneously declare and initialize a final
variable with the result of a complex expression?
In other words, is something like the following possible?
final int x = [capturedVariable] {
switch (capturedVariable) {
case 1: return 42;
case 2: return 84;
default: return 66;
}
};
While the syntax is obviously "creative", I hope the intent is clear.
Edit 1: While this particular example can be written using ternary operators, it's merely an example of a complex expression and I'm looking for a general solution.
Edit 2: Maybe a less controversial way to look at this question is the following: What is the syntax to simultaneously declare and invoke a lambda/closure in Java 8?