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