admin管理员组文章数量:1122855
【泛型
泛型-胡乱砍
- 1.define base interface
- 2.define a child interface
- 3. define a implement class
- 4.其他:辅助类
- 5.泛型--胡乱砍的说明
1.define base interface
public interface Generation<T,R,Entity> {R getName(T t, Entity entity);
}
2.define a child interface
public interface ERGeneration<T extends Person, R extends String, Entity extends Person> extends Generation<Person, String, Number> {R erStatus(T t, Entity entity);
}
3. define a implement class
package cn.gbase.admin.plugin.controller.test;import java.util.List;public class ERGenerationImpl<T extends Person,R extends String,Entity extends Child> implements ERGeneration<T, R, Entity> {public static void main(String[] args) {ERGenerationImpl<Person,String,Child> generation = new ERGenerationImpl<>();generation.erStatus(new Person("zhangsan",88),new Child("孙子1",2));generation.erStatus(new Child("tt",23),new Child("孙子2",2));}//@Override//public R erStatus(T t) {// return null;//}public R test(List<? super Child> list){Person p = (Person) list.stream().findFirst().get();return (R) p.getName();}@Overridepublic String getName(Person person, Number number) {return null;}@Overridepublic R erStatus(T t, Entity entity) {return null;}
}
4.其他:辅助类
// person类
import lombok.Data;@Data
public class Person {private String name;private int age;public Person(String zhangsan, int i) {}
}
// Child类
public class Child extends Person{public Child(String name, int age) {super(name, age);}
}
5.泛型–胡乱砍的说明
wait for me, tell you latter…
本文标签: 泛型
版权声明:本文标题:【泛型 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/biancheng/1730973869a1551756.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论