0

当我打开 TreeSet 类的源代码时,有以下代码:

public boolean contains(Object o) {
    return m.containsKey(o);
}

m 是一个 NavigableMap,它是一个接口。那么实施在哪里呢?它绝对不在 TreeSet 本身。

4

1 回答 1

1

From the source for TreeSet:

TreeSet(NavigableMap<E,Object> m) {
    this.m = m;
}

public TreeSet() {
    this(new TreeMap<E,Object>());
}

So m should be a TreeMap (or possibly another implementation of NavigableMap if another class in the same package calls that constructor).

于 2015-01-21T00:46:14.210 回答