Java의 capture of

murkgom·2023년 6월 16일
int captureValue = 1;
Runnable runnable = () -> System.out.printlin(captureValue);
runnable.run();

람다식이나 익명 클래스에서 외부 변수를 참조할 때, 외부 변수를 "capture"해서 사용한다는 개념

capture된 변수는 수정하려고 하면 컴파일 오류가 발생(= final)

0개의 댓글