java.util.Optional<T>
, java.util.OptionalDouble
, java.util.OptionalInt
,
java.util.OptionalLong
or com.google.common.base.Optional
as the type for a field or a parameter.
Optional was designed to provide a limited mechanism for library method return types where there needed
to be a clear way to represent "no result".
Using a field with type java.util.Optional
is also problematic if the class needs to be Serializable
,
which java.util.Optional
is not.
Example:
class MyClass { Optional<String> name; // Optional field void setName(Optional<String> name) { // Optional parameter this.name = name; } }
New in 2016.1