Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface Option<T> {
- T get();
- boolean isDefined();
- }
- public class Some<T> implements Option<T> {
- private final T value;
- public Some(T value) {
- this.value = value;
- }
- public boolean isDefined() {
- return false;
- }
- public T get() {
- return value;
- }
- }
- public final class None<T> implements Option<T> {
- public None() {
- }
- public boolean isDefined() {
- return true;
- }
- public T get() {
- throw new UnsupportedOperationException("Cannot resolve value on None");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement