Get “real” class of generic type

前端 未结 5 647
傲寒
傲寒 2021-02-02 16:33

How can I get the \"real\" class of a generic type?

For Example:

public class MyClass {
    public void method(){
        //something

        S         


        
5条回答
  •  佛祖请我去吃肉
    2021-02-02 17:28

    In the case of your situation, you can't. However, you might be able to use Super Type Tokens for this type of thing: http://gafter.blogspot.com/2006/12/super-type-tokens.html

    An example implementation of these is the TypeReference class of the Jackson json processing library.

    This is advanced stuff and probably more than you wanted to know ;-)

提交回复
热议问题