@Test public void testOrElse() { Assert.assertEquals(Optional.empty().orElse(2), 2); Assert.assertEquals(Optional.of(1).orElse(2), Integer.valueOf(1)); }
public T orElse(final T other) { if (isPresent()) { return this.get(); } else { return other; } }
Optional implements Serializable { public T orElse(final T other) { if (isPresent()) { return this.get(); } else { return other; } } }
Optional implements Serializable { public T orElse(final T other) { if (isPresent()) { return this.get(); } else { return other; } } private  Optional(final T value); private  Optional(); }
Optional implements Serializable { public T orElse(final T other) { if (isPresent()) { return this.get(); } else { return other; } } private  Optional(final T value); private  Optional(); static Optional<T> of(final T value); static Optional<T> empty(); static Optional<T> ofNullable(final T value); T get(); T orElse(final T other); boolean isPresent(); @Override boolean equals(final Object obj); @Override int hashCode(); @Override String toString(); }
Optional implements Serializable { public T orElse(final T other) { if (isPresent()) { return this.get(); } else { return other; } } private  Optional(final T value); private  Optional(); static Optional<T> of(final T value); static Optional<T> empty(); static Optional<T> ofNullable(final T value); T get(); T orElse(final T other); boolean isPresent(); @Override boolean equals(final Object obj); @Override int hashCode(); @Override String toString();  }