Get type of generic type inside a List in Java

前端 未结 7 2391
再見小時候
再見小時候 2021-02-15 22:58

I have the below function:


    public  void putList(String key, List lst){
          if (T instanceof String) {
          // Do something              


        
7条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-15 23:41

    Use the instanceof operator.

    That said, generic operations should be, well, generic, so be wary of changing behaviour based on type.

提交回复
热议问题