JAVA 泛型


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58
1, 在得到数据时不用再强制类型转换

      private Map powers = new HashMap();
    
    public void addModule( String moduleId, ModulePower mp ){
        powers.put( moduleId , mp );
        
    }
    
    public ModulePower findModuleById( String moduleId ){
        return powers.get( moduleId ); //自动识别为ModulePower
    }

2, 灵活

public interface List {

           void add(E x);

           Iterator iterator();

}

public interface Iterator {

           E next();

           boolean hasNext();

}
  // E 可为任意类型,可为除类型不一样,其它都一样的多个类提供模版,即提取出公共的类代码部分