title: Optional and casting at the same time
body: <p>I have a <code>BigDecimal</code> amount that I want to cast to <code>Long</code> if it is not <code>null</code>, but I got a <code>java.lang.NullPointerException</code> exception doing:</p>
  
  <pre><code>BigDecimal bgAmount = getAmount();
  
  long totalSupplyFilterMin = 
                Optional.ofNullable(bgAmount.longValue()).orElse(Long.MIN_VALUE);
  </code></pre>