Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

implementing the TypeVariable interface

0 views
Skip to first unread message

transkawa

unread,
Nov 17, 2009, 2:55:00 AM11/17/09
to
can anyone demonstrate to me how to implement the TypeVariable<D extends
GenericDeclaration> interface of the java.lang.reflect package?
would really be helpful for me to see an algorithm that implements
getBounds() and getGenericDeclaration(). am in the clouds from reading the
language spec.
xnt
david


markspace

unread,
Nov 17, 2009, 6:30:33 PM11/17/09
to


I don't think one would implement a TypeVariable. One gets an
implementation from an instance of java.lang.Class.

<http://java.sun.com/docs/books/tutorial/reflect/>

Short example:

import static java.lang.System.out;

....

/** method to list type parameters */
void listTypes( Object o ) {
Class c = o.getClass();
TypeVariable[] tv = c.getTypeParameters();
if (tv.length != 0) {
out.format(" ");
for (TypeVariable t : tv)
out.format("%s ", t.getName());
out.format("%n%n");
} else {
out.format(" -- No Type Parameters --%n%n");
}
}

I didn't test that, but most of it I got from that link I gave you. It
should work.


0 new messages