asList(T... a) java源码分析
程序员文章站
2022-07-13 16:01:43
...
/**
* Returns a fixed-size list backed by the specified array. (Changes to
* the returned list "write through" to the array.) This method acts
* as bridge between array-based and collection-based APIs, in
* combination with <tt>Collection.toArray</tt>. The returned list is
* serializable and implements {@link RandomAccess}.
*
* <p>This method also provides a convenient way to create a fixed-size
* list initialized to contain several elements:
* <pre>
* List<String> stooges = Arrays.asList("Larry", "Moe", "Curly");
* </pre>
*
* @param a the array by which the list will be backed.
* @return a list view of the specified array.
* @see Collection#toArray()
*/
public static <T> List<T> asList(T... a) {
return new ArrayList<T>(a);
}
从上面的说明中可以发现,他返回的是一个固定大小的list,所以后面如果你进行添加元素的操作时,他就会报unSupport Operation异常。
上一篇: Android 设置布局字体不随手机系统设置而改变
下一篇: mybatis 批量插入插件