Fetching size of object's list - Optional.get() without .ifPresent : <p>I have method that return <code>Optional</code> of Book object (do not mind with names as it is just a sample of code). I want to fetch the size of list which is inside Book class:</p>

<pre><code>public class Book {
    Integer b;

    DateTime dateOfCreation;

    Integer a;

    List&lt;Integer&gt; bookList;
}
</code></pre>

<p>So it goes like this: </p>

<pre><code>public class Main {
    public static void main(String[] args) {

        Optional&lt;Book&gt; book = getBookObject();
        int sizeOfList = book.get().bookList.size();
    }

    static Optional&lt;Book&gt; getBookObject() {
        return Optional.of(new Book());
    }
}
</code></pre>

<p>I have warning within the <code>get()</code> which goes like <code>Optional.get() without .ifPresent</code> what is the proper approach to fetch this size of the list?</p>
