java133-泛型

public class Employee {
    private String name;
    private String ags;
 
    public void setName(String name) {
        this.name = name;
    }
 
    public String getName() {
        return name;
    }
 
    public void setAgs(String ags) {
        this.ags = ags;
    }
 
    public String getAgs() {
        return ags;
    }
}
测试类

import java.util.ArrayList;
import java.util.List;
 
//泛型
public class test72 {
    public static void main(String[] args){
        List<Employee> empList=new ArrayList<Employee>();
        Employee emp1=new Employee();
        emp1.setName("歌谣");
        Employee emp2=new Employee();
        emp2.setName("小白");
        Employee emp3=new Employee();
        emp3.setName("小红");
        empList.add(emp1);
        empList.add(emp2);
        empList.add(emp3);
        for(Employee emp:empList){
            System.out.println(emp.getName());
        }
    }
}
结果

posted @ 2022-06-25 15:26  前端导师歌谣  阅读(22)  评论(0)    收藏  举报