implementing the TypeVariable interface

Discussion in 'Java' started by transkawa, Nov 17, 2009.

  1. transkawa

    transkawa Guest

    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
     
    transkawa, Nov 17, 2009
    #1
    1. Advertisements

  2. transkawa

    markspace Guest


    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.
     
    markspace, Nov 17, 2009
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.