Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.53 KB | None | 0 0
  1. public interface Option<T> {
  2.   T get();
  3.   boolean isDefined();
  4. }
  5.  
  6. public class Some<T> implements Option<T> {
  7.   private final T value;
  8.  
  9.   public Some(T value) {
  10.     this.value = value;
  11.   }
  12.  
  13.   public boolean isDefined() {
  14.     return false;
  15.   }
  16.  
  17.   public T get() {
  18.     return value;
  19.   }
  20. }
  21.  
  22. public final class None<T> implements Option<T> {
  23.   public None() {
  24.   }
  25.  
  26.   public boolean isDefined() {
  27.     return true;
  28.   }
  29.  
  30.   public T get() {
  31.     throw new UnsupportedOperationException("Cannot resolve value on None");
  32.   }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement