Closure is when a returned function still has access to the scope it was returned from. Learn how to use closure in Java and how it can be a helpful tool.
- [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 …
Skill Level Advanced
Java Design Patterns: Structuralwith Bethan Palmer1h 38m Intermediate
1. Introduction to Functional Programming
2. First-Class Functions
3. Working with Streams in Java
4. Advanced Concepts
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.