Advertisement
DulcetAirman

OptionalInt vs ?:

Aug 28th, 2018
121
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement