class User { private int id; private String name; private int age; public User(int id, String name, int age) { this.id = id; this.name = name; this.age = age; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } } interface GenericDao<T> { List<T> all(); } interface UserDao extends GenericDao<User> { } class UserDaoImpl implements UserDao { List<User>userList = new ArrayList<User>(); public UserDaoImpl() { //构造添加3行数据 userList.add( new User(1, "张三", 25)); userList.add(new User(2, "李四", 30)); userList.add(new User(3, "王五", 36)); } @Override public List all() { List<User>list = userList; return list; } } public class InterfaceDemo01 { public static void main(String[] args) { List<User> list = new UserDaoImpl().all(); for (User user : list) { System.out.println(user.getId() + " " + user.getName() + " " + user.getAge()); } } }