From the course: Functional Programming with Java

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Passing functions as arguments

Passing functions as arguments - Java Tutorial

From the course: Functional Programming with Java

Start my 1-month free trial

Passing functions as arguments

- So now that we've seen how we can treat functions in the same way as other types, such as integers, strings or other objects. The next step is to look at how we can pass functions as arguments to other functions. So up until now, you've probably been used to passing arguments into functions with the purpose of specifying what the data is that we're operating on. So if we pass two numbers into a function called add for example, we're specifying the two numbers that we want to add together. But what if instead of passing arguments into our function to specify what our data is, we could pass in arguments to specify what was done to that data. This is one of the important things that first class functions let us do. Now to illustrate this point let's imagine that we have a class called my math which we'll define up here. We're going to say protected, static class, my math. And let's say that this class has two very simple static methods. We'll call them add and subtract. So we're going…

Contents