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能实现权限控制和安全控制…