Java 8 Optional and flatMap - what is wrong?
问题 Some piece of code: public class Player { Team team; String name; } public class Team { List<Player> players; } public class Demo { @Inject TeamDAO teamDAO; @Inject PlayerDAO playerDAO; List<String> findTeamMatesNames(String playerName) { Optional<Player> player = Optional.ofNullable(playerDAO.get(playerName)); return player.flatMap(p -> teamDAO.findPlayers(p.team)) .map(p -> p.name) .orElse(Collections.emptyList()); } } Why am I not able to do this? In flatMap method I am getting error "Type