AToBFunction
A : 입력타입 B: 출력타입
IntToDoubleFunction : : public double applyAsDouble(int value)
IntToLongFunction : public long applyAsDouble(int value)
DoubleToIntFunction : public int applyAsDouble(double value)
DoubleToLongFunction : public long applyAsDouble(double value)
LongToIntFunction : public int applyAsDouble(long value)
LongToDoubleFunction : public double applyAsDouble(long value)
import java.util.function.*;
public class AToBFunctionExam {
public static void main(String[] args) {
IntToDoubleFunction intToDoubleFunction = new IntToDoubleFunction() {
@Override
public double applyAsDouble(int value) {
return value;
}
};
// 타입 검사
boolean result = Double.class.isInstance(intToDoubleFunction.applyAsDouble(10));
System.out.println(result);
IntToLongFunction intToLongFunction = new IntToLongFunction() {
@Override
public long applyAsLong(int value) {
return value;
}
};
// 타입검사
result = Long.class.isInstance(intToLongFunction.applyAsLong(10));
System.out.println(result);
}
}
/* 람다 */
import java.util.function.*;
public class AToBFunctionExam {
public static void main(String[] args) {
IntToDoubleFunction intToDoubleFunction = value -> value;
// 타입 검사
boolean result = Double.class.isInstance(intToDoubleFunction.applyAsDouble(10));
System.out.println(result);
IntToLongFunction intToLongFunction = value -> value;
// 타입검사
result = Long.class.isInstance(intToLongFunction.applyAsLong(10));
System.out.println(result);
}
}
댓글 영역