@Test public void testEquals() { Assert.assertEquals(Optional.empty(), Optional.empty()); Assert.assertEquals(Optional.empty(), Optional.ofNullable(null)); Assert.assertEquals(Optional.of(1), Optional.of(1)); Assert.assertEquals(Optional.of("one"), Optional.of("one")); Assert.assertFalse(Optional.of("one").equals(Optional.of("two"))); }
@Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null || getClass() != obj.getClass()) { return false; } final Optional that = (Optional) obj; return this.value == that.value || this.value != null && this.value.equals(that.value); }
Optional implements Serializable { @Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null || getClass() != obj.getClass()) { return false; } final Optional that = (Optional) obj; return this.value == that.value || this.value != null && this.value.equals(that.value); } }
Optional implements Serializable { @Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null || getClass() != obj.getClass()) { return false; } final Optional that = (Optional) obj; return this.value == that.value || this.value != null && this.value.equals(that.value); } private  Optional(final T value); private  Optional(); }
Optional implements Serializable { @Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null || getClass() != obj.getClass()) { return false; } final Optional that = (Optional) obj; return this.value == that.value || this.value != null && this.value.equals(that.value); } 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 { @Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null || getClass() != obj.getClass()) { return false; } final Optional that = (Optional) obj; return this.value == that.value || this.value != null && this.value.equals(that.value); } 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();  }