IntToLongFunction
IntToLongFunction (int→long 함수형 인터페이스)
int 값 인자를 받아 long 값 결과를 생성하는 함수를 나타내는 함수형 인터페이스예요. Function의 int-to-long 원시 특수화예요.
본문
IntToLongFunction의 추상 메서드는 applyAsLong(int)로 int 인자를 받아 long을 반환해요.
@FunctionalInterface
public interface IntToLongFunction
IntToLongFunction factorial = n -> {
long r = 1;
for (int i = 2; i <= n; i++) r *= i;
return r;
};
IntToLongFunction square = n -> (long) n * n;
long f = factorial.applyAsLong(5); // 120
long s = square.applyAsLong(9); // 81
IntStream의 값을 LongStream으로 변환할 때 사용해요.
LongStream ls = IntStream.of(2, 3, 4).mapToLong(n -> (long) n << 1);
함수형 메서드는 applyAsLong(int)예요. 코드와 시그니처는 원문 그대로 보존돼요.