I was reading Object Oriented Javascript and found the concept of closures. I didn’t quite understand why and when it is used. Do other languages like Java also have closures? I basically want to understand how knowing the concept of closures can help me improve my coding.
I was reading Object Oriented Javascript and found the concept of closures. I didn’t
Share
A closure is a first class function with bound variables.
Roughly that means that:
Java initially didn’t have syntactic support for closures (these were introduced in Java 8), although it was fairly common practice to simulate them using anonymous inner classes. Here’s an example: