MCPcopy
hub / github.com/google/guava / fromNullable

Method fromNullable

guava/src/com/google/common/base/Optional.java:119–121  ·  view source on GitHub ↗

If {@code nullableReference} is non-null, returns an {@code Optional} instance containing that reference; otherwise returns {@link Optional#absent}. <p><b>Comparison to {@code java.util.Optional}:</b> this method is equivalent to Java 8's {@code Optional.ofNullable}.

(@Nullable T nullableReference)

Source from the content-addressed store, hash-verified

117 * {@code Optional.ofNullable}.
118 */
119 public static <T> Optional<T> fromNullable(@Nullable T nullableReference) {
120 return (nullableReference == null) ? Optional.<T>absent() : new Present<T>(nullableReference);
121 }
122
123 /**
124 * Returns the equivalent {@code com.google.common.base.Optional} value to the given {@code

Callers 4

getEnumIfPresentMethod · 0.95
fromJavaUtilMethod · 0.95
testFromNullableMethod · 0.95
testFromNullable_nullMethod · 0.95

Calls 1

absentMethod · 0.95

Tested by 2

testFromNullableMethod · 0.76
testFromNullable_nullMethod · 0.76