区别:与new HashMap() 与 new ArrayList() 没啥区别,主要目的是为了简化,不需要你手动写泛型。
1:添加依赖:
<!-- google java lib --> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>17.0</version> </dependency>
2:实现方式
HashMap<Object, Object> map = Maps.newHashMap(); List<Object> list = Lists.newArrayList();
3:Maps.newHashMap() 部分源码
public static <K, V> HashMap<K, V> newHashMap() { return new HashMap(); }
4: Lists.newArrayList() 部分源码
public static <E> ArrayList<E> newArrayList() { return new ArrayList(); }