Generics

Recently I tried to find a reliable way to obtain actual types for generic types at runtime. Of course, I know that anyone with some sense will say that it's impossible.

The funny thing however: under some circumstances it is possible. What are these circumstances? I wish I knew.

Working through the java.lang.reflect API is not that easy with regard to generics. Performing tests is even harder, at least for me: there are so many paths that must be explored that I soon tend to get lost.

XML representation

I decided that I needed a reliable way to collect all info (specific to generics) I could find from a class. So I wrote a very simple utility that explores a class and displays the info via an XML file in the browser.

I can't show the results via web start, because one must feed it with some class. But the source code can be downloaded here.

Disclaimer: not all code is mine. I borrowed AbstractObjectReader and EasyGenerationContentHandlerProxy from the demo's supplied with the Apache FOP project.

The utility class DisplayAsXML has a static method test(Object obj). When invoked with a Class argument, info about that class will be displayed. When invoked with any other argument, info about the class of the argument will be displayed.

Did I get any the wiser?

No, not really. I can't see the wood because of the trees. I will have to do more reading on the subject.

Some links that are helpful