Created
August 8, 2016 01:34
-
-
Save A-pZ/15190eef32d5c35b557176338687a780 to your computer and use it in GitHub Desktop.
ラムダ式と実質的final
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package seren.example.questions; | |
import java.util.Arrays; | |
import java.util.List; | |
import org.junit.Test; | |
/** | |
* @author A-pZ | |
*/ | |
public class StreamTest { | |
@Test | |
public void test() { | |
int value = 10; | |
List<Integer> arrays = Arrays.asList(1, 2, 3, 4, 5); | |
arrays.stream().forEach(element -> { | |
// これはコンパイルエラー。ラムダ式の中からローカル変数を変更してはいけない。 | |
// このルールはローカルクラスからメソッドのローカル変数を利用するときの制限と同じ仕様で | |
// ローカル変数の扱いは不変でなければならない。 | |
value = +1; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment