import .*;
import ;
class User {
private Integer age;
private String name;
public User(Integer age, String name) {
this.age = age;
this.name = name;
}
public String getName() {
return name;
}
public Integer getAge() {
return age;
}
public String toString() {
return "User{" +
"age=" + age +
", name='" + name + '\'' +
'}';
}
}
public class Main {
public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
List<User> userList = new ArrayList<>();
(new User(3, "Tom"));
(new User(2, "Ana"));
(new User(99, "Bob"));
(new User(1, "Lyly"));
(new User(4, "Lyly"));
// 正确,对象映射成名字
// List<String> nameList = ().map(User::getName).collect(());//[Tom, Ana, Bob, Lyly, Lyly]
// 正确,对象映射成名字
List<String> nameList = ().map(user -> ()).collect(());//[Tom, Ana, Bob, Lyly, Lyly]
//错误
List<String> nameList = ().forEach(user -> ()).collect(());
(nameList);
}
}