示例#1
0
 public void testBasicAnonymousClass() throws Exception {
   Function h =
       new Function() {
         @Override
         public Object apply(Object x) {
           return x;
         }
       };
   assertEquals(42, h.apply(42));
 }
示例#2
0
 public void testBasicFunction() throws Exception {
   Function f = x -> x;
   assertEquals(42, f.apply(42));
   Function<Integer, Integer> f2 = x -> x;
   assertEquals((Integer) 42, f2.apply(42));
   Function f3 =
       x -> {
         int y = 42;
         return y;
       };
   assertEquals(42, f3.apply(null));
   FourToOne<String, Double, Integer, Boolean, String> appendFour = (a, b, c, d) -> a + b + c + d;
   assertEquals("Foo4.214true", appendFour.apply("Foo", 4.2, 14, true));
 }
示例#3
0
 // Tests outer reference resolution, and that inner fields are being correctly resolved for
 // lambdas with implicit blocks.
 public void testAdditionInLambda() throws Exception {
   Function f =
       new Function<Integer, Integer>() {
         @Override
         public Integer apply(Integer x) {
           return x + 20;
         }
       };
   assertEquals(42, f.apply(22));
   Function<Integer, Integer> g =
       x -> {
         return x + 20;
       };
   assertEquals((Integer) 42, g.apply(22));
   Function<Integer, Integer> h = x -> x + 20;
   assertEquals((Integer) 42, h.apply(22));
 }
示例#4
0
 public void testStaticFunctions() throws Exception {
   assertEquals(42, staticF.apply(42));
 }