I read that Java 8
supports Closures
, but I just wanted to know that as any function
inside a class
can access a global variable, so how can Java previously didn't support Closures
?? See below example.
public class HelloWorld{
int number = 5;
public void fun() {
System.out.println("number: " + number); // Here fun() can access number.
}
public static void main(String []args){
System.out.println("Hello World");
new HelloWorld().fun();
}
}
I think there is something about Closures
which I didn't get ??