BAEL2489 - Avoid check for null statement in Java (#6411)
* 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
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package com.baeldung.nulls;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class UsingOptional {
|
||||
|
||||
public Optional<Object> process(boolean processed) {
|
||||
|
||||
String response = doSomething(processed);
|
||||
|
||||
if (response == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return Optional.of(response);
|
||||
}
|
||||
|
||||
private String doSomething(boolean processed) {
|
||||
|
||||
if (processed) {
|
||||
return "passed";
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user