/** * Returns an Optional with the specified present non-null value. * * @param value the value to be present, which must be non-null * @return an Optional with the value present */ public static <T> Optional<T> of(@NonNull T value){ return new Optional<>(value); }
/** * Returns an Optional describing the specified value, if non-null, otherwise returns an empty Optional. * * @param value the possibly-null value to describe * @return an Optional with a present value if the specified value is non-null, otherwise an empty Optional */ public static <T> Optional<T> ofNullable(T value){ if(value == null){ return empty(); } return new Optional<>(value); }