Class RuntimeTypes


  • public final class RuntimeTypes
    extends java.lang.Object
    Stores the classes from the compile-time generic type parameters in a vector in the *same order* as the generics in the type signature of that class. Store them here using registerClasses(Class[]) to avoid duplication. For example:
    private static final ImList CLASS_STRING_INTEGER =
        RuntimeTypes.registerClasses(vec(String.class, Integer.class));
    Now you if you use CLASS_STRING_INTEGER, you are never creating a new vector. For a full example of how to use these RuntimeTypes, see OneOf2. This is an experiment in runtime types for Java. Constructive criticism is appreciated! If you write a programming language, your compiler can manage these vectors so that humans don't have to ever think about them, except to query them when they want to. I wanted to do this with arrays, but I didn't trust that they wouldn't be mutated, so I used ImList's.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String name​(java.lang.Class c)  
      static ImList<java.lang.Class> registerClasses​(java.lang.Class... cs)
      Use this to prevent duplicate runtime types.
      static java.lang.String union2Str​(java.lang.Object item, ImList<java.lang.Class> types)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • registerClasses

        public static ImList<java.lang.Class> registerClasses​(java.lang.Class... cs)
        Use this to prevent duplicate runtime types.
        Parameters:
        cs - an immutable vector of classes to register
      • name

        public static java.lang.String name​(java.lang.Class c)
      • union2Str

        public static java.lang.String union2Str​(java.lang.Object item,
                                                 ImList<java.lang.Class> types)