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

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -