Passing ArrayList to method declared with List

前端 未结 1 2040
清歌不尽
清歌不尽 2020-12-17 09:32

I have a method with a parameter containing generics.

public static void readList(List list)
{
    // more code
}

I want

1条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-17 09:40

    You can use wildcards, if you're using Java version 1.5 and higher.

    public static void readList(List list)
    

    This solution is more generic, because it fits for all java.util.List interface implementations and subclasses/subinterfaces of ModelObject. For more details go to wildcards tutorial

    0 讨论(0)
提交回复
热议问题