mercredi 20 janvier 2016

Java Optional - If Else Statements

So after some reading I've seen that

if (optional.isPresent()) {
    //do smth
}

is not the preferred way to use Optional (http://ift.tt/1pgVZmt). But if I have an if-statement like this:

if (optional.isPresent()) {
    car = getCar(optional.get());
} else {
    car = new Car();
    car.setName(carName);
}

Is this the best way to do this or is there a more recommended way?

Aucun commentaire:

Enregistrer un commentaire