I Wish Java Had Good Generics
Do you see the problem with this code?
// map from url as a string to content for that url
// apparently URL.equals() is bad:
// http://javaantipatterns.wordpress.com/2007/11/24/comparing-urls-with-urlequals/
private static Map<String, String> urlCache = Maps.newHashMap();
private static String getURLContent(URL url) throws IOException {
if (urlCache.containsKey(url.toString())) {
return urlCache.get(url);
}
// ...
}
I wish it wouldn’t even compile.
(Problem: using url instead of url.toString() in get())