请教linkedlist源代码,有点没明白什么意思。public int indexOf(Object o) {int index 0if (onull) {f
请教linkedlist源代码,有点没明白什么意思。
public int indexOf(Object o) { int index = 0; if (o==null) { for (Entry e = header.next; e != header; e = e.next) { if (e.element==null) return index; index++; } } else { for (Entry e = header.next; e != header; e = e.next) { if (o.equals(e.element)) return index; index++; } } return -1; }
if (o==null) { for (Entry e = header.next; e != header; e = e.next) { if (e.element==null) return index; index++; } } 这一部分什么意思?o==null? [解决办法] o==null的时候分开来讨论因为o是null的话没有办法调用方法(会报错),所以也不能用下面的