[英]Implementation of isEmpty()
I'm trying to figure some basic things out. 我试图弄清楚一些基本的东西。 I was exploring standard library ArrayList.java when found that ArrayList has implementation of method isEmpty().
当我发现ArrayList具有方法isEmpty()的实现时,我正在探索标准库ArrayList.java。
ArrayList.java: ArrayList.java:
public boolean isEmpty() {
return size == 0;
}
ArrayList extends AbstractList extends AbstractCollection. ArrayList扩展AbstractList扩展AbstractCollection。 And AbstractCollection has implementation of isEmpty as well:
并且AbstractCollection也具有isEmpty的实现:
public boolean isEmpty() {
return size() == 0;
}
I'm just trying to get the logic? 我只是想弄清楚逻辑? Why ArrayList implements already implemented method?
为什么ArrayList实现已经实现的方法? What for?
做什么的?
PS ArrayList also has size PS ArrayList也有大小
public int size() {
return size;
}
ArrayList版本是次要但有效的优化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.