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 believe this class is thread-safe.
    • Method Detail

      • registerClasses

        @NotNull
        public static @NotNull ImList<Class> registerClasses​(@NotNull
                                                             @NotNull Class @NotNull ... cs)
        Use this to register runtime type signatures
        Parameters:
        cs - an array of types
        Returns:
        An immutable vector of those types. Given the same types, always returns the same vector.
      • name

        @NotNull
        public static @NotNull String name​(@Nullable
                                           @Nullable Class c)
      • union2Str

        @NotNull
        public static @NotNull String union2Str​(Object item,
                                                @NotNull
                                                @NotNull ImList<Class> types)