I’m curious if there are things in the standard class library that you find useful but not widely used.

  • austin@programming.dev
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    1 year ago

    Optional has more syntactic sugar for more complex scenarios / functional call chaining that prevents repetitive if checks

    Optional.ofNullable(myObj)
      .map(MyClass::getProperty)
      .map(MyOtherClass::getAnotherProperty)
      .filter(obj -> somePredicate(obj))
      .orElse(null)
    

    This is completely null safe, the function calls are only made if the object is not null