public static void main(String[] args) {
Student student = new Student();
Aaa aaa = new Aaa();
Bbb bbb = new Bbb();
bbb.setName("恭喜你");
aaa.setBbb(bbb);
student.setAaa(aaa);
Object end = Optional.ofNullable(student)
.map((a) -> a.getAaa())
.map((b) -> b.getBbb())
.map((n) -> n.getName())
.orElse(null);
System.out.println(end);
}
网友评论