diff --git a/src/sandbox/GeneralCompare.java b/src/sandbox/GeneralCompare.java new file mode 100644 index 0000000000000000000000000000000000000000..29332aa981890f0b026d7bc1bdca632304f21563 --- /dev/null +++ b/src/sandbox/GeneralCompare.java @@ -0,0 +1,5 @@ +package sandbox; + +public interface GeneralCompare<T> { + public int eval(T a1, T a2); +} diff --git a/src/sandbox/TestLambdas.java b/src/sandbox/TestLambdas.java index 69ac2bc4ac76ff8d89bbf350715f975842e96eef..91dc35c0120ef2193dd16f11cc8e5e4a4c8f975e 100644 --- a/src/sandbox/TestLambdas.java +++ b/src/sandbox/TestLambdas.java @@ -7,9 +7,9 @@ package sandbox; public class TestLambdas { public static void main(String[] args) { //declare the instances of BinaryIntExpression - BinaryIntExpression b0; - BinaryIntExpression b1; - BinaryIntExpression b2; + GeneralCompare<Integer> b0; + GeneralCompare<Integer> b1; + GeneralCompare<Integer> b2; BinaryIntExpression b3; BinaryIntExpression b4; BinaryIntExpression b5; @@ -34,13 +34,13 @@ public class TestLambdas { }; //call the main function using the instances as a parameter. - result = binaryOperation(1,2,b0); + result = binaryIntegerOperation(1,2,b0); System.out.println(result); - result = binaryOperation(1,2,b1); + result = binaryIntegerOperation(1,2,b1); System.out.println(result); - result = binaryOperation(1,2,b2); + result = binaryIntegerOperation(1,2,b2); System.out.println(result); result = binaryOperation(1,2,b3); @@ -61,4 +61,9 @@ public class TestLambdas { return exp.eval(a1, a2); } + public static int binaryIntegerOperation(int a1, int a2, GeneralCompare<Integer> exp) { + //call the eval() function in the given BinaryIntExpression. + return exp.eval(a1, a2); + } + }