User user = new User(“[email protected]”, “1234”);标签:flatmap,String,user,使用,position,gmail,java8,getPosition,User From: https://blog.51cto.com/u_7341513/6090168
user.setPosition(“Developer”);
String position = Optional.ofNullable(user)
.flatMap(u -> u.getPosition()).orElse(“default”);assertEquals(position, user.getPosition().get());