Announce - Orthodox Type Reflection Library
By Tim on Thursday, February 21 2008, 23:39 - Development - Permalink
Prior to the release of Java 5, the Java library had 1 class that provided access to type information at runtime - java.lang.Class. However, with the introduction of generics in Java 5, this has been extended significantly. Dealing with all these classes, and working with them at runtime, is overly complex, and reduces the power of generics.
Orthodox is a library that makes it easier to work with the Java type system at runtime.
In Java 5, the type system includes the interfaces:
java.lang.reflect.Typejava.lang.reflect.ParameterizedTypejava.lang.reflect.WildcardTypejava.lang.reflect.TypeVariablejava.lang.reflect.GenericArrayTypejava.lang.reflect.GenericDeclaration
Have you ever tried to use those interfaces? It's not straight forward.
Imagine a class com.example.Bean has a method
getList() that returns an object of type
java.util.List. You want to know what type of object that list
will contain. Is it a list of Objects? A list of Strings? Something else?
If we look at the source code, we might see:
List< ? extends CharSequence > getList() { /* ... */ }
But how do we get access to that information at runtime? You might think it's impossible, due to type erasure, but the information is actually there, it's just that it's hard to get to because of all those different ways of representing a type.
Orthodox makes it easy to get at that information (and much more).
At the moment it's a 0.5 release, because it hasn't had enough real world
usage to be sure that the API is right. Since the whole point of orthodox is to
put a better API on top of java.lang.reflect.Type, getting the API
right is important. And I don't want to declare it a 1.0 release until I'm
happy that I've achieved that.
However, don't let the 0.5 tag scare you into thinking it's unstable or untested - I've put it through its paces, and it works like a charm.