Created
October 9, 2019 09:42
-
-
Save bmaggi/e476dcb51361a378c2ca45b6b2eb6882 to your computer and use it in GitHub Desktop.
Small reminder that orElse parameter is evaluated
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Optional; | |
public class FunIsOptional { | |
public static void main(String[] args) { | |
Integer i = 0; | |
System.out.println(Optional.of(i).map(v -> v++).orElse(i--)); | |
// => res = 0 (orElse is evaluated even when not empty) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment