Class RuntimeTypes


  • public final class RuntimeTypes
    extends 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 Detail

      • registerClasses

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