blob: 647cb2b28beeaf884312bcefbda2e649f37fda4b [file] [log] [blame]
import java.util.Optional;
/**
* Test case for rule #4: "It's generally a bad idea to create an Optional for the specific purpose
* of chaining from it to get a value."
*/
public class Marks4 {
String getDefault() {
return "Fozzy Bear";
}
String process_bad(String s) {
// :: warning: (introduce.eliminate)
return Optional.ofNullable(s).orElseGet(this::getDefault);
}
String process_good(String s) {
return (s != null) ? s : getDefault();
}
}