About Question enthuware.ocpjp.v8.2.1766 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
sreeharshitha
Posts: 4
Joined: Wed Jul 10, 2019 11:41 pm
Contact:

About Question enthuware.ocpjp.v8.2.1766 :

Post by sreeharshitha »

a Supplier interface takes no input but returns a value. In this, name::toUpperCase, will take name="bob" as input right?

admin
Site Admin
Posts: 10065
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1766 :

Post by admin »

When we say that a functional interface takes no input, it actually means that the functional method of that functional interface takes no input.

So, no, there is no input to the toUpperCase method. It is invoked on the String reference. Think of it like this:

Code: Select all

String name = "bob";
Supplier<String> s = new Supplier(){
      String get(){
         return name.toUpperCase();
      }
  };
The above is what Supplier<String> s = name::toUpperCase; is translated into.
If you like our products and services, please help us by posting your review here.

thienday
Posts: 1
Joined: Sat Dec 16, 2023 2:11 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1766 :

Post by thienday »

Hi admin, can you write a topic about the method reference in Java. When i have to face it i have some conclusion like this :
If it use the variable to get method like this example. When run time it compile to lambda like variable.method(name.toUpercase)
If it use the class and use the instance method like String::isEmpty. When run time it compile to lambda like parameter.method(s -> s.isEmpty())
If it use static method like Class::staticmethod When run time it compile to lambda like Class.staticmethod(parameter)

yulinxp
Posts: 12
Joined: Sat Dec 02, 2023 12:54 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1766 :

Post by yulinxp »

Check out here https://javadevcentral.com/java-method-references The best of best...

Post Reply

Who is online

Users browsing this forum: No registered users and 236 guests