A value retrieved from a type-specific collection does not need to be casted
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
public class Main {
public static void main(String[] argv) {
Map<String, URL> urlMap = new HashMap<String, URL>();
try {
urlMap.put("java", new URL("http://www.java2s.com"));
} catch (MalformedURLException e) {
}
String s = urlMap.get("java").getHost();
}
}
Related examples in the same category