Package org.organicdesign.fp.type
Class RuntimeTypes
- java.lang.Object
-
- org.organicdesign.fp.type.RuntimeTypes
-
public final class RuntimeTypes extends java.lang.ObjectStores 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 usingregisterClasses(Class[])to avoid duplication. For example:
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, seeprivate static final ImListCLASS_STRING_INTEGER = RuntimeTypes.registerClasses(vec(String.class, Integer.class)); 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.Stringname(java.lang.Class c)static ImList<java.lang.Class>registerClasses(java.lang.Class... cs)Use this to prevent duplicate runtime types.static java.lang.Stringunion2Str(java.lang.Object item, ImList<java.lang.Class> types)
-
-
-
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)
-
-