About Question enthuware.ocpjp.v8.2.1766 :
Moderator: admin
-
- Posts: 4
- Joined: Wed Jul 10, 2019 11:41 pm
- Contact:
About Question enthuware.ocpjp.v8.2.1766 :
a Supplier interface takes no input but returns a value. In this, name::toUpperCase, will take name="bob" as input right?
-
- Site Admin
- Posts: 10067
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1766 :
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:
The above is what Supplier<String> s = name::toUpperCase; is translated into.
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();
}
};
If you like our products and services, please help us by posting your review here.
-
- Posts: 1
- Joined: Sat Dec 16, 2023 2:11 am
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1766 :
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)
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)
-
- Posts: 12
- Joined: Sat Dec 02, 2023 12:54 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1766 :
Check out here https://javadevcentral.com/java-method-references The best of best...
Who is online
Users browsing this forum: Bing [Bot] and 216 guests