-
-
Notifications
You must be signed in to change notification settings - Fork 367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider add Optional<T>
as in java.util with the very same behavior and scope
#661
Comments
Isn't that exactly what Nullable is? You already have that in |
While Check this presentation to have a reasoning about the needs of Like Oracle guys says: More over container some useful high-level methods which allows to deal with "absent" value like the followings (from Java 8 doc):
Obviously, all these methods could be easily implemented also in the current nullable types, it is just more explicit. The strong similarity with nullables is what stopped me so far from implement Note:
was always false, even for the very same type, if one type comes from a binary (let's say an executable) and from a bpl (as a result from function or method). |
A container object which may or may not contain a non-null value.If a value is present, isPresent() returns true. If novalue is present, the object is considered empty and isPresent() returns false.
Additional methods that depend on the presence or absence of a containedvalue are provided, such as orElse()(returns a default value if no value is present) and ifPresent() (performs anaction if a value is present).
This is a value-basedclass; programmers should treat instances that are equal as interchangeable and should notuse instances for synchronization, or unpredictable behavior mayoccur.
Type Parameters: the type of value
Optional is primarily intended for use as a method return type wherethere is a clear need to represent "no result," and where using null is likely to cause errors. A variable whose type is Optional should never itself be null; it should always point to an Optional instance.
The text was updated successfully, but these errors were encountered: