From the course: Functional Programming with Java
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Closure - Java Tutorial
From the course: Functional Programming with Java
Closure
- [Instructor] In a previous video, we talked about how in Java it's possible to return functions from other functions, and we saw some possible applications of doing this in our code base. So returning functions from other functions leads us to another very important concept in Java, and this is something called closure. So what is closure exactly? Well, basically, closure means that when we define a function that returns another function, the function that we return still has access to the internal scope of the function that returned it. So to see exactly what I mean here, let's code out an example that demonstrates closure. The first thing we're going to do is we're going to create a function called createGreeter. This is going to be pretty similar to what we just saw when we looked at returning functions. So we're going to say NoArgFunction, and this function is going to return a string, and we'll call it createGreeter, and what this function is going to do is it's simply going to…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.