* BAEL2489 - Avoid check for null statement in Java * BAEL2489 Avoid check for null statement in Java * BAEL2489 Avoid check for null statement in Java * BAEL2489 Avoid check for null statement in Java * BAEL2489 Avoid check for null statement in Java * BAEL2489 Avoid check for null statement in Java - Removing unused pom changes * BAEL2489 Avoid check for null statement in Java - Removing unused pom changes * Delete pom.xml Removing unused changes in core-java * BAEL2489 Avoid check for null statement in Java - Removing unused pom changes * BAEL2489 Avoid check for null statement in Java - adding ofnullable to Optional example
24 lines
417 B
Java
24 lines
417 B
Java
package com.baeldung.nulls;
|
|
|
|
import java.util.Optional;
|
|
|
|
public class UsingOptional {
|
|
|
|
public Optional<Object> process(boolean processed) {
|
|
|
|
String response = doSomething(processed);
|
|
|
|
return Optional.ofNullable(response);
|
|
}
|
|
|
|
private String doSomething(boolean processed) {
|
|
|
|
if (processed) {
|
|
return "passed";
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
}
|