Created
June 16, 2020 18:56
-
-
Save yenerm/6ae30d577b8e2a1f8d48fac6cf2c0c0d to your computer and use it in GitHub Desktop.
Optional Sample
This file contains 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
<!-- Copyright 2019 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
Optional<String> opt = Optional.of("Java 8"); | |
if (opt.isPresent()){ //true | |
//... | |
} | |
opt = Optional.ofNullable(null); | |
if (opt.isEmpty()){ //true | |
//… | |
} | |
opt.ifPresent(str -> System.out.println(str)); //false, doesn’t print |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment