I cannot do this in Java:
Optional optStr = Optional.of(\"foo\");
String result;
optStr.ifPresent(s -> result = s);
The doc sa
Another way, similar to what Tunaki has written, is to use a single-cell table:
Optional optStr = Optional.of("foo");
String[] temp = new String[1];
optStr.ifPresent(s -> temp[0] = s);
String result = temp[0];
The table object is final, what changes is its content.
Edit: A word of warning though - before using this hacky solution check out the other answers to OP's question, pointing out why it's a bad idea to use this workaround and consider if it's really worth it!