创建extends泛型对象
public static <T extends Animal> T create(Supplier<T> supplier) {
T t = supplier.get();
t.setName("Tom");
t.setColor("Black");
t.setAge(10);
return t;
}
@Data
static class Animal {
private String name;
private String color;
private Integer age;
}
@Data
@ToString(callSuper = true)
static class Cat extends Animal {
private String hasBanner;
}
@Test
public void testGeneric() {
Animal animal = create(Animal::new);
Cat cat = create(Cat::new);
System.out.println(animal);
System.out.println(cat);
}