Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Introduction to Functional Programming Meet Streams Mapping Player's Names

Haisam Elkewidy
Haisam Elkewidy
26,987 Points

Getting error that says to use the method reference to get the player. Don't know what that means.

com.teamtreehouse.challenges.highscores.MainTest > mapIsUsedWithMethodReference FAILED java.lang.AssertionError: Please make use of the method reference in your 'getFirstFiveAmazingPlayersDeclaratively' method to get the player at org.junit.Assert.fail(Assert.java:88) at org.junit.Assert.assertTrue(Assert.java:41) at com.teamtreehouse.challenges.highscores.MainTest.mapIsUsedWithMethodReference(MainTest.java:82)

code:

 public static List<String> getFirstFiveAmazingPlayersDeclaratively(List<Score> scores) {
    // TODO: Filter where amount is greater than 100,000
    // TODO: Map to the player's name
    // TODO: Limit to 5
    // TODO: And collect those strings and return them
    return scores.stream()
      .filter(score -> score.getAmount() > 100000)
      .map(Main::getScorePlayers)
      .limit(5)
      .collect(Collectors.toList());

  }

  public static String getScorePlayers(Score score) {

    String player = score.getPlayer();

    return player;

  }

1 Answer

You should use .map(Score::getPlayer) instead of .map(Main::getScorePlayers) in stream chain.