Get “real” class of generic type

前端 未结 5 636
傲寒
傲寒 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:34

    You can't. The information is stripped from the code at compile time, a process that is known as type erasure. For more, please look here: Type Erasure

    edit: sorry my bad, the information is not loaded at run time.

提交回复
热议问题