devxlogo

April 29, 2019

Return a Boolean if the Optional Is Empty

Beginning with JDK 11, we can return a boolean if the Optional is empty via Optional#isEmpty(): public boolean bookIsEmpty(long id) { Optional book = // code that fetches the book