@Override
public Option<V> get (final K key) {
- return Option.makeOption (null);
+ return Option.makeOption();
}
@Override
}
@Override
- public Option<V> get (final K key) {
- if(key.equals (k)) {
- return Option.makeOption (v);
+ public Option<V> get(final K key) {
+ if (key.equals(k)) {
+ return Option.makeOption(v);
}
- if(next != null) {
- return next.get (key);
+ if (next != null) {
+ return next.get(key);
}
- return Option.makeOption (null);
+ return Option.makeOption();
}
*
* @param <V>
*/
-@SuppressWarnings({"rawtypes", "unchecked"})
-class Option<V> {
- static None none = new None();
- public static <V> Option<V> makeOption(final V o){
- if(o!=null) {
+abstract class Option<V> {
+ private static final None<?> NONE = new None<>();
+
+ static <V> Option<V> makeOption(final V o) {
+ if (o != null) {
return new Some<>(o);
- } else {
- return none;
}
- }
- public static <V> Option<V> makeOption(){
- return none;
+ return makeOption();
}
- public boolean nonEmpty () {
- return false;
+
+ @SuppressWarnings("unchecked")
+ static <V> Option<V> makeOption() {
+ return (Option<V>) NONE;
}
+
+ abstract boolean nonEmpty();
}