Skip to content

Instantly share code, notes, and snippets.

@gamlerhart
Created December 2, 2010 21:26
Show Gist options
  • Save gamlerhart/726103 to your computer and use it in GitHub Desktop.
Save gamlerhart/726103 to your computer and use it in GitHub Desktop.
old-school-collections.java
// Annoying double declaration of the generic arguments
List<String> strings = new ArrayList<String>();
// Even more annoying
Map<String,URI> cityToWebsite = new HashMap<String,URI>();
public class CollectionUtils {
private CollectionUtils(){
}
public static <T> List<T> list(){
return new ArrayList<T>();
}
public static <T> List<T> list(T...elements){
return new ArrayList<T>(asList(elements));
}
public static <T> Set<T> set(){
return new HashSet<T>();
}
public static <T> Set<T> set(T...elements){
return new HashSet<T>(asList(elements));
}
public static <TKey,TValue> Map<TKey,TValue> map(){
return new HashMap<TKey,TValue>();
}
}
List<String> strings = list();
List<String> moreStrings = list("Hi","There");
Set<String> setOfStrings = set();
Map<String,URI> cityToWebsite = map();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment