• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

BiPredicate List::contains

 
Greenhorn
Posts: 13
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys , i am Levent ,
I am preparing OCP8 for upgrade my OCP6 certificate.

As you know ;



how can be this code valid ?
0)contains method is not static.
boolean contains(Object o)

1) and method should be like ;
boolean contains(Object  , Object)
boolean contains(List , Integer)



A Comprehensive OCPJP 8 Certication Guide



Thank you.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Before Java 8 you would create this anonymous class to do exactly the same

And to fix your compiler error, you need something like

So the method signature of your static containsTwo method is actually containsTwo(List<Integer> list, Integer num) (if you try to switch these parameter types, you'll get a compiler error).
 
Bartender
Posts: 5465
212
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What helped me when it comes to understanding method references was to write out lambda's with explicit parameters. Once I got the hang of that, it turned out to be relatively easy to start understanding and using method references. For instance, have a look at a simplified version of your class. At first I use lambda's with explicit parameters, that gives me a clue how many parameters are involved. Then it is easy to write equivalent versions that use method references. See if this makes sense:
 
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Piet Souris wrote:What helped me when it comes to understanding method references was to write out lambda's with explicit parameters.


Good advice for those of us, like me, who need to know about lambdas and the Predicate interface for the OCA 1Z0-808 exam.

Thanks.
 
Levent Erguder
Greenhorn
Posts: 13
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for replies
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic