Skip to content

Instantly share code, notes, and snippets.

@bmaggi
Created October 9, 2019 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmaggi/e476dcb51361a378c2ca45b6b2eb6882 to your computer and use it in GitHub Desktop.
Save bmaggi/e476dcb51361a378c2ca45b6b2eb6882 to your computer and use it in GitHub Desktop.
Small reminder that orElse parameter is evaluated
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