Created
December 2, 2010 21:26
-
-
Save gamlerhart/726103 to your computer and use it in GitHub Desktop.
old-school-collections.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Annoying double declaration of the generic arguments | |
List<String> strings = new ArrayList<String>(); | |
// Even more annoying | |
Map<String,URI> cityToWebsite = new HashMap<String,URI>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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