请问Map map = new HashMap;与Map map = Maps.Hashmap;创建的map对象有什么区别?

请问Map map = new HashMap;与Map map = Maps.Hashmap;创建的map对象有什么区别?

阅读 12.2k
2 个回答

没什么区别,你看下源码就知道了:

/**
   * Creates a <i>mutable</i>, empty {@code HashMap} instance.
   *
   * <p><b>Note:</b> if mutability is not required, use {@link
   * ImmutableMap#of()} instead.
   *
   * <p><b>Note:</b> if {@code K} is an {@code enum} type, use {@link
   * #newEnumMap} instead.
   *
   * @return a new, empty {@code HashMap}
   */
  public static <K, V> HashMap<K, V> newHashMap() {
    return new HashMap<K, V>();
  }
新手上路,请多包涵

你说的是com.google.common.collect.Maps.newHashMap()吗?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题