今天打开jre1.6.0_27 HashMap values()方法源码
389 public Set<K> keySet()
390 {
391 Set localSet = this.keySet;
392 return (this.keySet = new KeySet(null));
393 }
394
395 public Collection<V> values()
396 {
397 Collection localCollection = this.values;
398 return (this.values = new Values(null));
399 }
我认为这些源代码是错误的,但我不知道为什么它们看起来像这样。谁能告诉我为什么?
========================================
谢谢大家,我认为这是Eclipse的问题,这个源代码我使用Eclipse F3并去了它,所以它看起来像上面那个。
我刚打开src.zip,这个方法源码是对的。
/**
* Returns a {@link Collection} view of the values contained in this map.
* The collection is backed by the map, so changes to the map are
* reflected in the collection, and vice-versa. If the map is
* modified while an iteration over the collection is in progress
* (except through the iterator's own <tt>remove</tt> operation),
* the results of the iteration are undefined. The collection
* supports element removal, which removes the corresponding
* mapping from the map, via the <tt>Iterator.remove</tt>,
* <tt>Collection.remove</tt>, <tt>removeAll</tt>,
* <tt>retainAll</tt> and <tt>clear</tt> operations. It does not
* support the <tt>add</tt> or <tt>addAll</tt> operations.
*/
903 public Collection<V> values() {
904 Collection<V> vs = values;
905 return (vs != null ? vs : (values = new Values()));
906 }