Java Function Interface

  • apply() (Abstract Method for Functional Interface) -> Applies this function to the given argument.
  • compose() (Default Method)-> Returns a composed function that first applies the before function to its input, and then applies this function to the result.
  • andThen() (Default Method) ->Returns a composed function that first applies this function to its input, and then applies the after function to the result.
  • identity() (Default Method) -> Returns a function that always returns its input argument.

Function<T,R> func = doSomething(return R Type);

func.apply(T type param);

/*
* A Function interface takes the Integer parameter and returns a
* Double type value that returns the Square of the value;
*/
Function<Integer,Double> square = s -> Math.pow(s,2);
System.out.println(square.apply(5));
//Output : 25
UnaryOperator<String> unaryOperator = s -> s.toUpperCase();
System.out.print(unaryOperator.apply("hey"));
//Output : HEY

--

--

--

Software Engineer , Berlin , @devyigitk twitter

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

3 (Very Human) Reasons Software Projects Fail

Now hiring: Senior Front-End Developer

On building real products as a self-taught developer

Learning an Assembly Language: Goofing around with instructions

Azure Sentinel — Day 28

House Price Prediction 🏡

Getting Started in Python in 2020

Samsung T839 Sidekick 4g User Manual

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yigit Kader

Yigit Kader

Software Engineer , Berlin , @devyigitk twitter

More from Medium

JAVA File Handling

ArrayList in Java

Sorter in Java