Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
Streams
Effectively final variable.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// {
class Main {
public static void main(String[] args) {
// }
//Incorrect
for (int i = 0; i < 10; i++) {
new Thread(() -> {
System.out.println("i = " + i); // Does not compile!
}).start();
}
// {
}
}
// }
Press desired key combination and then press ENTER.
1
2
3
4
5
6
7
8
9
10
11
12
13
// {
class Main {
public static void main(String[] args) {
// }
for (int i = 0; i < 10; i++) {
int j = i; //effectively final
new Thread(() -> System.out.println("i = " + j)).start();
}
// {
}
}
// }
Press desired key combination and then press ENTER.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// {
class Main {
public static void main(String[] args) {
// }
//Incorrect
for (int i = 0; i < 10; i++) {
int j = i;
new Thread(() -> System.out.println("i = " + j)).start();
j++;
}
// {
}
}
// }
Press desired key combination and then press ENTER.
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content