This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Lambda / predicate  RSS feed

 
Laimonas Oberauskis
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi folks, above is a perfectly working code. However, I would like to know how does one write the line "check(animalList, a -> a.isPurrer());" with full lambda signature (signature blueprint is like this: (Animal a) -> { return a.canHop(); } ).
And one more question, how often are lambdas and predicates used in a real life coding?
Thanks in advance!
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you seen the details of the Stream#filter() method, the Predicate interface and the appropriate part of the Java™ Tutorials about nested classes? You might only need the last link.
You end up with something like
 
Campbell Ritchie
Marshal
Posts: 55717
163
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can probably condense that Predicate to a method reference.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!