Buildin System Functional Interfaces

Description

Java 8 has functional interfaces in the package java.util.function.

Function

To represent a function that takes an argument of type T and returns a result of type R.


public interface Function<T,R>{
   ...//w ww  . ja  va2  s .  c o  m
   public R apply(T t);
   ...
}

BiFunction

To represent a function that takes two arguments of types T and U, and returns a result of type R.


public interface BiFunction<T,U,R>{
   ...// w ww  .j  av  a 2  s  .  c o m
   public R apply(T t, U u);
   ...
}         

Predicate

To represent a boolean function that returns true or false for the specified argument.


public Predicate<T> {
   .../*from w  w w  .  j a v a 2 s .c om*/
   public boolean test(T  t);
   ...
}

BiPredicate

To represent a boolean function that returns true or false for the two specified arguments.


public interface BiPredicate<T,U>{
   ...//from w  ww  .  ja  va  2 s  . co  m
   public boolean test(T t, U u);
   ...   
}

Consumer

To represent an operation that takes an argument and returns no result.


public interface Consumer<T>{
   .../*w w  w  . ja  va  2  s .c  o m*/
   public void accept(T t);
   ...
}

BiConsumer

To represent an operation that takes two arguments and returns no result.


public interface BiConsumer<T,U>{
   ...   //from ww  w. ja  v a2  s . c  om
   public void accept(T t, U  u);
   ...   
}

Supplier

To represent a function that returns a value as of type T.


public interface Supplier<T>{
   ...//from   w w w.  j  a  va2  s. com
    public T get();
   ...
}

UnaryOperator

To represent a function that takes an argument and returns a result of the same type.


public interface UnaryOperator<T>{
   ...//from w  w w  .  j  a  va2s . co m
   public T  apply(T t);
   ...
}

BinaryOperator

To represent a function that takes two arguments and returns a result of the same type.


public interface BinaryOperator<T>{
   .../*  ww w  . ja va  2  s .c  o m*/
   public T apply(T t1, T t2);
   ...
}           

Note

The above generic buildin functional interfaces are all the generic versions of more specialized functional interfaces.

For example, IntConsumer is a specialized version of Consumer<T>.





















Home »
  Java Lambda »
    Java Lambda Tutorial »




Java Lambda Tutorial