두 정수의 합 구하기 Closure Literal.
{int x, int y => x+y}
두 정수의 합 구하기 Closure를 지역 변수 plus에 할당하기
-
- {int,int=>int} plus = {int x, int y => x+y};
{int,int=>int} plus = {int x, int y => x+y};
내부적으로는 위와 같은 literal들이 translation 됩니다. 예를들어,
-
- {int,String=>Number throws IOException} xyzzy;
{int,String=>Number throws IOException} xyzzy;
와 같은 변수 선언은
-
- interface Closure1<R,A2,throws E> {
- R invoke(int x1, A2 x2) throws E;
- }
- Closure1<? extends Number,? super String,null> xyzzy;
interface Closure1<R,A2,throws E> { // system-generated
R invoke(int x1, A2 x2) throws E;
}
Closure1<? extends Number,? super String,null> xyzzy;
와 같이 변환됩니다.
Control Invocation Syntax의 예
-
- withLock(lock) {
- System.out.println("hello");
- }
withLock(lock) {
System.out.println("hello");
}
file 처리의 예
-
- with(FileReader in : makeReader()) with(FileWriter out : makeWriter()) {
-
- }
흐미..
0