当前位置: 代码迷 >> Java相关 >> ArrayList中的add方法没有返回值为什么不报错?
  详细解决方案

ArrayList中的add方法没有返回值为什么不报错?

热度:225   发布时间:2007-02-07 19:04:22.0
ArrayList中的add方法没有返回值为什么不报错?

import java.util.ArrayList;
public class A
{
public static void main(String[] args)
{
ArrayList a=new ArrayList();
a.ensureCapacity(2);
a.add(new Stu("da","da"));
a.add(new Stu("ds","dd"));
a.add(new Stu("ada","dddd"));
int m=a.size();
System.out.println("it is:"+m);
}
}
class Stu
{
.............

API:
(add
public boolean add(E o)将指定的元素追加到此列表的尾部。

指定者:
接口 Collection<E> 中的 add
指定者:
接口 List<E> 中的 add
覆盖:
类 AbstractList<E> 中的 add
参数:
o - 要追加到此列表中的元素。
返回:
true(按照 Collection.add 的常规协定)。)

谢谢。

搜索更多相关的解决方案: ArrayList  add  返回值  

----------------解决方案--------------------------------------------------------
为什么要报错?
----------------解决方案--------------------------------------------------------
这个方法不是有返回值的吗?

----------------解决方案--------------------------------------------------------
是啊 但是你可以不操作返回值啊
----------------解决方案--------------------------------------------------------
谢谢了。
明白了。

----------------解决方案--------------------------------------------------------
  相关解决方案