32 lines
811 B
Java
Raw Normal View History

2015-04-20 15:36:01 -07:00
//: net/mindview/util/New.java
// Utilities to simplify generic container creation
// by using type argument inference.
package net.mindview.util;
import java.util.*;
public class New {
public static <K,V> Map<K,V> map() {
2015-05-05 11:20:13 -07:00
return new HashMap<>();
2015-04-20 15:36:01 -07:00
}
public static <T> List<T> list() {
2015-05-05 11:20:13 -07:00
return new ArrayList<>();
2015-04-20 15:36:01 -07:00
}
public static <T> LinkedList<T> lList() {
2015-05-05 11:20:13 -07:00
return new LinkedList<>();
2015-04-20 15:36:01 -07:00
}
public static <T> Set<T> set() {
2015-05-05 11:20:13 -07:00
return new HashSet<>();
2015-04-20 15:36:01 -07:00
}
public static <T> Queue<T> queue() {
2015-05-05 11:20:13 -07:00
return new LinkedList<>();
2015-04-20 15:36:01 -07:00
}
// Examples:
public static void main(String[] args) {
Map<String, List<String>> sls = New.map();
List<String> ls = New.list();
LinkedList<String> lls = New.lList();
Set<String> ss = New.set();
Queue<String> qs = New.queue();
}
} ///:~