HashMap returned by Java What is the collection of values () methods?

Java se 6.0 API util. The values () method in HashMap returns a collection type How does the JVM decide which collection to return at run time Is it the JVM or the general guidelines followed by Java I browsed the source code of HashMap, but I couldn't get a clue Any help is very appreciated, or if the problem is lame, please click my reason thank you.

Solution

You can see the source:

public Collection<V> values() {
    if (values == null) {
        values = new AbstractCollection<V>() {
          ...

They actually gave a custom implementation of abstractcollection

An important thing to know about this collection is that it is not serializable: never try to send it between client and server

Note that this excerpt is from the sun JDK source This means that it is vendor - specific

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>