JackbyDev ( JackbyDev@programming.dev ) M to Java@programming.dev · 3 years agoWhat are some things in the class library you wish more people knew about or used?docs.oracle.comexternal-linkmessage-square18linkfedilinkarrow-up114file-text
arrow-up114external-linkWhat are some things in the class library you wish more people knew about or used?docs.oracle.comJackbyDev ( JackbyDev@programming.dev ) M to Java@programming.dev · 3 years agomessage-square18linkfedilinkfile-text
I’m curious if there are things in the standard class library that you find useful but not widely used.
minus-squareaustin ( austin@programming.dev ) linkfedilinkEnglisharrow-up1·3 years agoOptional 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
Optional has more syntactic sugar for more complex scenarios / functional call chaining that prevents repetitive
ifchecksOptional.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