lundi 14 novembre 2016

How to check if null and have specific value with Optional in java?

Assume that i have this code in my project:

public List<T> getAll(Integer parameter) {
    if(parameter != null && parameter > -1) {
        // do something here
    }
}

my question is that how can i do the checking with Optional instead of using if, or if there is another thing that can i use it, please introduce it to me.

Aucun commentaire:

Enregistrer un commentaire