Advertisement
DulcetAirman

OptionalInt vs ?:

Aug 28th, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.25 KB | None | 0 0
  1.   public static void main(String[] args) {
  2.     Integer stockPrice = getStockPrice();
  3.     int i = OptionalInt.ofNullable(stockPrice).orElse(0);
  4.     int j = stockPrice == null ? 0 : stockPrice;
  5.   }
  6.  
  7.   static Integer getStockPrice() {
  8.     return null;
  9.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement