Cannot convert from List to List

前端 未结 3 1860
情歌与酒
情歌与酒 2020-11-28 12:54

A raw list converts to List just fine. Why can\'t a list of raw lists convert to a list of List?

{   // works
            


        
3条回答
  •  盖世英雄少女心
    2020-11-28 13:24

    You cannot assign or cast it directly, because raw type List isn't the same as List.

    When using List type checking is ignored and you may use any generic method with any type. When using List the compiler won't let you use methods with generic parameters.


    Therefore you could either ignore the warnings:

    @SuppressWarnings("rawtypes")
    

    And/Or cast it explicitly with a workaround:

    List> raw = (List>) ((Object)api());
    

提交回复
热议问题