Refactor Optional examples
This commit is contained in:
parent
037acd1ae6
commit
dcb7221d29
|
@ -66,7 +66,6 @@ public class OptionalTest {
|
|||
public void givenOptional_whenIfPresentWorks_thenCorrect() {
|
||||
Optional<String> opt = Optional.of("baeldung");
|
||||
opt.ifPresent(name -> System.out.println(name.length()));
|
||||
opt.ifPresent(String::length);
|
||||
}
|
||||
|
||||
// returning Value With get()
|
||||
|
@ -185,12 +184,6 @@ public class OptionalTest {
|
|||
.orElseGet(() -> "john");
|
||||
assertEquals("john", name);
|
||||
|
||||
name = Optional.ofNullable(nullName)
|
||||
.orElseGet(() -> {
|
||||
return "doe";
|
||||
});
|
||||
assertEquals("doe", name);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue