Class Nil<T>

  • All Implemented Interfaces:
    GenericTyped, Proxyable<T>

    public abstract class Nil<T>
    extends Object
    implements GenericTyped, Proxyable<T>
    A "typed null" which knows its generic type, and can generate proxy objects implementing that type's interfaces, with customizable behavior per interface method via callbacks.

    The term "nil" was chosen, despite lots of possibility for confusion with related paradigms such as the Scala language, because it is very short while loosely meaning the same thing as null, None, etc.

    Author:
    Curtis Rueden
    • Constructor Detail

      • Nil

        public Nil()
        Creates a new Nil whose generic type (returned by type()) is the one specified by the generic parameters used at construction.

        For example:

         Nil<List<Map<K, V>>> nil = new Nil<List<Map<K, V>>>() {};
         

        Subsequent calls to nil.type() will return the proper generically typed result—in the above example, a ParameterizedType whose raw type is List, and whose single type parameter is a ParameterizedType with raw type of Map and TypeVariable type parameters of K and V respectively, including their bounds inferred by the compiler in the context where the expression was written.

      • Nil

        public Nil​(Object callbacks)
    • Method Detail

      • of

        public static <T> Nil<T> of​(Class<T> rawType)
      • of

        public static Nil<?> of​(Type type)
        Creates a Nil of the given generic Type, with no extra method callbacks.
      • of

        public static Nil<?> of​(Type type,
                                Object callbacks)
        Creates a Nil of the given Type, with extra method callbacks contained in the specified object.
      • proxy

        public T proxy()
        Create a proxy which implements all the same interfaces as this object's generic type.

        Optionally, CTR FIXME - write up how method delegation works.

        Specified by:
        proxy in interface Proxyable<T>