Mega Code Archive

 
Categories / Java / Generics
 

A value retrieved from a type-specific list does not need to be casted

import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.List; public class Main {   public static void main(String[] argv) {     List<URL> urlList = new ArrayList<URL>();     try {       urlList.add(new URL("http://www.rntsoft.com"));     } catch (MalformedURLException e) {     }     String s = urlList.get(0).getHost();   } }