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…

本文标签: 泛型