Java - Generics with lists

后端 未结 5 1021
悲&欢浪女
悲&欢浪女 2020-12-21 13:52

I wrote a function for my cache to retrieve a specific object. This way I don\'t need to cast it .

@SuppressWarnings(\"unchecked\")
    public static 

        
5条回答
  •  情深已故
    2020-12-21 14:35

    Try this-

    List inList = (List)Test.inCache(List.class, title);
    

    And you can do also -

    List inList = Test.inCache((Class>)List.class, token);
    

提交回复
热议问题