Definition – In Java 8 a Function Descriptor is a term used to describe the signature of the abstract method of a Functional Interface
Click to Read tutorial on Java 8 Functional Interfaces. The signature of the abstract method of a Functional Interface is syntactically the same as the signature of the Lambda Expression
Click to Read Java 8 Lambda Expressions tutorial. Hence, a Function Descriptor also describes the signature of a lambda.
Examples of function descriptors
To illustrate let us see a few examples of function descriptors –
Example 1: Lets say we have a functional interface named FirstInterface. It’s described as below –
package com.javabrahman.java8; @FunctionalInterface public interface FirstInterface { //Single abstract method public void singleMethod(String param); }
Example 2: Functional Interface SecondInterface.java has a slight variation of the abstract method –
package com.javabrahman.java8; @FunctionalInterface public interface SecondInterface { //Single abstract method public long computeSum(int num1, int num2); }
Example 3: Java’s in-built java.lang.Runnable interface has a single public void run() method. The function descriptor for Runnable interface will be () -> void
Example 4: Lets see an example of a generic type based in-built functional interface named Function<T, R> introduced in Java 8 –
@FunctionalInterface public interface Function<T, R> { /** * Applies this function to the given argument. * @param t the function argument * @return the function result of type R */ R apply(T t);
