invoiceId = optionalInvoiceIDInfo.isPresent() ? optionalInvoiceIDInfo.get().getInvoiceID() : null; code example
Example 1: check if optional is empty java
@Test
public void givenNull_whenCreatesNullable_thenCorrect() {
String name = null;
Optional<String> opt = Optional.ofNullable(name);
assertFalse(opt.isPresent());
}
Example 2: check if optional is empty java
String o = getOptional().orElse(null);
if (o == null) {
return;
}