Is there a more concise way of creating an Optional.ofNullable of specified type without assigning it to the variable?
The working solution:
public Optional<V> getValue2(K key) {
Node<K, V> node = getNode(key);
Optional<V> nullable = Optional.ofNullable(null);
return isNull(node) ? nullable : Optional.ofNullable(node.getValue());
}
Here I get an error: "Type mismatch: cannot convert from Optional to Optional"
public Optional<V> getValue(K key) {
Node<K, V> node = getNode(key);
return isNull(node) ? Optional.ofNullable(null) : Optional.ofNullable(node.getValue());
}