toString() a generic type in Java

Posted by davidrobles on Stack Overflow See other posts from Stack Overflow or by davidrobles
Published on 2010-04-01T00:46:34Z Indexed on 2010/04/01 0:53 UTC
Read the original article Hit count: 342

Filed under:
|

How can I print the type of a generic java type?

Reflection? Any tricks?

public class Foo<K> {

    private K element;

    @Override
    public String toString() {
        return "Type: " + K;
    }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about generics