The first function Function<ApplyService, Class<? extends ApplyService>> f1 = ApplyService::run; is equivalent to :

Function<ApplyService, Class<? extends ApplyService>> f1 = apService -> apService.run();

So, while passing an object of type ApplyService1 the implemented method in ApplyService1 is invoked.

But the second function Function<ApplyService, Class<? extends ApplyService>> f2 = Abc::run2; is equivalent to :

Function<ApplyService, Class<? extends ApplyService>> f2 = apService -> Abc.run2(apService);

Since Abc::run2 is static method reference, the input ApplyService object is passed to the run2 method.

Answer from Gautham M on Stack Overflow
🌐
ConcretePage
concretepage.com › java › jdk-8 › function-apply-in-java-8
Function.apply in Java
Function&ltStudent,String&gt styleTwo = s-&gt "Name:"+s.name +" and Age:"+s.age; In third way, define function in a single line. So customShow() method will accept the Function instance and the apply() method of Function will execute how the function is defined. Find the complete example. FunctionDemo.java ·
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › function › Function.html
Function (Java Platform SE 8 )
July 21, 2026 - Java™ Platform Standard Ed. 8 ... This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference. @FunctionalInterface public interface Function<T,R> Represents a function that accepts one argument and produces a result. This is a functional interface whose functional method is apply(Object).
🌐
Javabrahman
javabrahman.com › java-8 › java-8-java-util-function-function-tutorial-with-examples
Java 8 java.util.function.Function Tutorial with Examples
In the code above it takes as input a parameter t of Type T and returns back this t. Usage of apply() method of Function The below code shows example usage of apply() method where it converts/maps from a list of Employee types to a list of Strings containing the names of all Employees. Let us now go through the code after which I will explain how the apply() method works - Java 8 code example showing usage of Function.apply() method
🌐
Mkyong
mkyong.com › home › java8 › java 8 function examples
Java 8 Function Examples | mkyong.com
February 27, 2020 - package com.mkyong; import java.util.function.Function; public class JavaMoney { public static void main(String[] args) { Function<String, Integer> func = x -> x.length(); Integer apply = func.apply("mkyong"); // 6 System.out.println(apply); } }
🌐
Java Guides
javaguides.net › 2023 › 09 › java-function-apply.html
Java Function apply()
September 27, 2023 - Using the apply() method, we then compute and print the results. The first function transforms the number 5 into its string form, while the second function doubles the number 7 to produce 14.
🌐
Java2s
java2s.com › Tutorials › Java › java.util.function › Function › 1020__Function.apply.htm
Java Lambda - Function apply example
Function apply applies this function to the given argument. apply has the following syntax. R apply(T t) The following example shows how to use apply. import java.util.function.Function; //from ww w .
🌐
GeeksforGeeks
geeksforgeeks.org › java › function-interface-in-java
Function Interface in Java - GeeksforGeeks
July 17, 2026 - import java.util.function.Function; // Main class public class Geeks { // main driver method public static void main(String args[]) { // Function which takes in a number and // returns half of it Function<Integer, Double> half = a -> a / 2.0; // Now triple the output of half function half = half.andThen(a -> 3 * a); // Applying the function to get the result // and printing on console System.out.println(half.apply(10)); } } ... This example demonstrates that the andThen() method throws a NullPointerException when a null function is passed instead of a valid function.
Top answer
1 of 2
1

The first function Function<ApplyService, Class<? extends ApplyService>> f1 = ApplyService::run; is equivalent to :

Function<ApplyService, Class<? extends ApplyService>> f1 = apService -> apService.run();

So, while passing an object of type ApplyService1 the implemented method in ApplyService1 is invoked.

But the second function Function<ApplyService, Class<? extends ApplyService>> f2 = Abc::run2; is equivalent to :

Function<ApplyService, Class<? extends ApplyService>> f2 = apService -> Abc.run2(apService);

Since Abc::run2 is static method reference, the input ApplyService object is passed to the run2 method.

2 of 2
1

ApplyService::run is a "Reference to an instance method of an arbitrary object of a particular type" as described here. Notice how run is an instance method, so you would need an instance to call it. You didn't specify any instance of ApplyService in the method reference (you just said ApplyService::run), so instead, when you invoke the method reference, the first argument you pass to apply is used as the instance on which to call the instance method.

In this case, new ApplyService1() is the instance on which you call run, so when you do:

f1.apply(new ApplyService1())

you are actually calling:

new ApplyService1().run()

Notice how the argument becomes the instance on which you call the method.

In the case of Abc::run2, it is a "Reference to a static method", so none of that "parameter becoming the instance on which you call the method" shenanigan happens, and it works as you expect.

Find elsewhere
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Get-the-most-from-Java-Function-interface-with-this-example
A simple Java Function interface example
Control decimal places, grouping, signs, padding and field width with compact Java 15 printf examples. ... Use Java 25's IO class with String.formatted for Strings, integers, floating-point values, dates, times and aligned console tables. ... If you want to understand functional programming in Java, the java.util.function.Function interface is one of the best places to start. A Function<T,R> accepts one value of type T and returns one value of type R. Its single abstract method is named apply.
Published: December 5, 2025
🌐
Javaprogramto
javaprogramto.com › 2020 › 05 › java-8-function-examples.html
Function Interface in Java with Examples (apply() and Chain Methods andThen(), identity())
December 1, 2020 - You can define in the interface default methods which have a body. These are introduced in Java 8. Observer the code and it needs two types T and R. And also it as a one functional method R apply(T t) which means it takes one input argument and returns a value.
🌐
freeCodeCamp
freecodecamp.org › news › functional-programming-in-java
Functional Programming in Java
January 20, 2026 - You can use the function interface ... example, you can use it to convert a list of objects of one type to a list of objects of another type, or to apply a series of transformations to a stream of data....
🌐
Baeldung
baeldung.com › home › java › core java › functional interfaces in java
Functional Interfaces in Java | Baeldung
March 26, 2025 - Learn how to apply if/else logic to Java 8 Streams. ... Java 8 brought a powerful new syntactic improvement in the form of lambda expressions. A lambda is an anonymous function that we can handle as a first-class language citizen.
🌐
Medium
medium.com › javaguides › java-function-functional-interface-with-real-world-examples-a1e86ea0fda5
Java Function Functional Interface with Real-World Examples | by Ramesh Fadatare | JavaGuides | Medium
March 1, 2025 - Learn how to use Java’s Function functional interface with a real-world example. Explore apply(), andThen(), compose(), and identity()…
🌐
Level Up Lunch
leveluplunch.com › java › examples › java-util-function-function-example
Java 8 function example | Level Up Lunch
March 9, 2014 - The Stream.map will apply the given function to all the elements in the stream. In this case, for every person object in person list, it will call the mapPersonToJob returning a Job object. We will then call the Stream.collect to convert the stream to a list. @Test public void map_objects_with_java8_function() { List<Person> persons = Lists.newArrayList(new Person(1, "Husband"), new Person(2, "Dad"), new Person(3, "Software engineer"), new Person(4, "Adjunct instructor"), new Person(5, "Pepperoni hanger")); List<Job> jobs = persons.stream().map(mapPersonToJob) .collect(Collectors.toList()); logger.info(jobs); assertEquals(5, jobs.size()); }
🌐
Tabnine
tabnine.com › home › code library
Code Library - Tabnine
July 25, 2024 - Get the answers and suggestions you need from our AI code assistant. Get started in minutes with a free 90 day trial of Tabnine Pro.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-bifunction-interface-methods-apply-and-andthen
Java | BiFunction Interface methods - apply() and andThen()
June 20, 2026 - ... Returns: This method returns ... void main(String args[]) { // BiFunction to add 2 numbers BiFunction<Integer, Integer, Integer> add = (a, b) -> a + b; // Implement add using apply() System.out.println("Sum = " + ...
🌐
GeeksforGeeks
geeksforgeeks.org › function-interface-in-java-with-examples
Function Interface in Java with Examples | GeeksforGeeks
August 7, 2024 - The Function Interface is a part ... in Java. It represents a function which takes in one argument and produces a result. Hence this functional interface takes in 2 generics namely as follows: ... The lambda expression assigned to an object of Function type is used to define its apply() which eventually ...
🌐
o7planning
o7planning.org › 13497 › java-function
Java Function Tutorial with Examples | o7planning.org
package java.util.function; import java.util.Objects; @FunctionalInterface public interface Function<T, R> { R apply(T t); default <V> Function<V, R> compose(Function<? super V, ? extends T> before) { Objects.requireNonNull(before); return (V v) -> apply(before.apply(v)); } default <V> Function<T, ...
🌐
ExamClouds
examclouds.com › home › java core › function interface in java
Java Function Interface: apply, andThen, compose, identity
December 22, 2016 - Function<Exam, String> converter = e -> e.getName() + " " + e.getVersion(); System.out.println(converter.apply(new Exam("Java Core", "8"))); System.out.println(converter.apply(new Exam("Java Core", "17"))); System.out.println(converter.apply(new ...