Acquiring generic class type

前端 未结 5 1651
轻奢々
轻奢々 2021-01-02 19:40

Hi is there any way in Java to get staticly generic class type

I have ended up with construct

    List l = new ArrayList&         


        
5条回答
  •  北荒
    北荒 (楼主)
    2021-01-02 20:30

    You can get the class for List, which would be Class c = List.class. Unfortunately in Java information about generics isn't retained in runtime so after compilation your List will become simply List.

提交回复
热议问题