Function Descriptor

by Santosh K Saha | Category Java-8


The signature of the abstract method in functional interface describes the signature of the lambda expression. Functional descriptor is used to represent this signature of lambda expression.


Lets understand the function descriptor with examples


Example 1

Function interface with method that takes no parameter and returns void

Function Descriptor : () -> void

@FunctionalInterface
public interface FunctionalInterfaceOne {
	
	public void abc();  // ()->void
	
}

Example 2

Function interface with method that takes String as a parameter and returns void

Function Descriptor : (String) -> void

@FunctionalInterface
public interface FunctionalInterfaceTwo {

	public void xyz(String name);  // (String)->void
	
}

Example 3

Function interface with method that takes two long as a parameter and returns double

Function Descriptor : (long, long) -> double

@FunctionalInterface
public interface FunctionalInterfaceThree {

	public double mno(long i, long j);  // (long, long)->double
	
}


Common functional interfaces in Java 8 and their function descriptor


Supplier<T>

Function Descriptor : () -> T

@FunctionalInterface 
public interface Supplier<T> {
	 T get(); 
}

Consumer<T>

Function Descriptor : T -> void

@FunctionalInterface 
public interface Consumer<T> {

	void accept(T t); 
	
}

BiConsumer<T, U>

Function Descriptor : (T, U) -> void

@FunctionalInterface 
public interface BiConsumer<T, U>  {

	void accept(T t, U u); 
	
}

BiConsumer<T, U>

Function Descriptor : (T, U) -> void

@FunctionalInterface 
public interface BiConsumer<T, U>  {

	void accept(T t, U u); 
	
}

Predicate<T>

Function Descriptor : T -> boolean

@FunctionalInterface
public interface Predicate<T>  {

	boolean test(T t); 
	
}

BiPredicate<T, U>

Function Descriptor : (T, U) -> boolean

@FunctionalInterface
public interface BiPredicate<T, U>  {

	boolean test(T t, U u); 
	
}

Function<T, R>

Function Descriptor : (T) -> R

@FunctionalInterface
public interface Function<T, R>  {

	 R apply(T t); 
	
}

BiFunction<T, U, R>

Function Descriptor : (T, U) -> R

@FunctionalInterface
public interface BiFunction<T, U, R>  {

	R apply(T t, U u); 
	
}
Note: Like our facebook page to get updated of free classes and tutorials.