ArrayList list =newArrayList();ArrayList<Object> list =newArrayList<>()
傳入子類型的說明
publicclass pra {publicstaticvoidmain(String[] args){animal<a> a =new animal<a>(newa());animal<a> b =new animal<a>(newb());}}class a{}class b extends a{}class animal<T>{T e;// 構造器publicanimal(T e){this.e = e;}publicvoidgetclass(){System.out.println(e.getClass());}}
說明:指定了animal類只能存儲 a 類對象,但是 b 類是 a 的子類,即 animal 類既可以是 a 對象也可以是 b 對象
5. 簡單的泛型案例
publicclass pra {publicstaticvoidmain(String[] args){HashMap<String,student> hashMap =newHashMap<>();hashMap.put("18",newstudent("jackson"));hashMap.put("20",newstudent("jack"));hashMap.put("23",newstudent("jom"));// 先取出entrysetSet<Map.Entry<String, student>> entries = hashMap.entrySet();// 構建迭代器(指向單例集合)Iterator<Map.Entry<String, student>> iterator = entries.iterator();while(iterator.hasNext()){Map.Entry<String, student> next = iterator.next();System.out.println("key:"+ next.getKey()+" value:"+ next.getValue());}}}class student{String name;publicstudent(String name){this.name = name;}@OverridepublicStringtoString(){return"student{"+"name='"+ name +'\''+'}';}}
Spring Boot的Security安全控制
在Web項目開發中,安全控制是非常重要的,不同的人配置不同的權限,這樣的系統才安全。最常見的權限框架有Shiro和Spring Security。Shiro偏向于權限控制,而Spring Security能實現權限控制和安全控制…