if statement - Java 8 Optional instead of if -
i have problem optional , don't know how handle it.
public void check(string name) { if (name != null) dosomething(name); else domore(); }
how change if optional?
there neat method that, present in jdk-9...
public void check(string name){ optional.ofnullable(name) .ifpresentorelse(yourclass::dosomething, yourclass::domore); }
assuming dosomething
, domore
static methods... if not instance should used, this::dosomething
or this::domore
Comments
Post a Comment