• Post Reply Bookmark Topic Watch Topic
  • New Topic

Lambda / predicate

 
Laimonas Oberauskis
Greenhorn
Posts: 7
  • 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: 53140
124
  • 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: 53140
124
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can probably condense that Predicate to a method reference.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!