diff options
| author | 2015-11-10 16:49:45 -0800 | |
|---|---|---|
| committer | 2015-11-11 10:15:17 -0800 | |
| commit | 152ee552652691ecaec2db420d468cb178647952 (patch) | |
| tree | c85f570f4b5e646003be7d15299cd429ba23feef /test/956-checker-lambda/src/Main.java | |
| parent | 972c5a62051ccd4558bc8956262183fe3ec466a4 (diff) | |
lambda: unit test for lambda expressions at Java Language source level.
Rationale: having a checkers-flavored unit test will enable testing
both if the correct HIR is generated using the checker
as well as the correctness of execution (interpreter for now,
but native code later).
Change-Id: I588e9955efaaf53e5c5e3398399e009041cd65f0
Diffstat (limited to 'test/956-checker-lambda/src/Main.java')
| -rw-r--r-- | test/956-checker-lambda/src/Main.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test/956-checker-lambda/src/Main.java b/test/956-checker-lambda/src/Main.java new file mode 100644 index 0000000000..b5f4a94b9e --- /dev/null +++ b/test/956-checker-lambda/src/Main.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// Test on lambda expressions. +// +public class Main { + + @NeedsLambda + interface L1 { + public void run(int a); + } + + int d; + + public Main() { + d = 4; + } + + private void doit(int a) { + int b = 2; + // Captures parameter, local, and field. Takes its own parameter. + // TODO: add field d as well, b/25631011 prevents this + L1 lambda1 = (int c) -> { System.out.println("Lambda " + a + b + c); }; + lambda1.run(3); + } + + public static void main(String[] args) { + new Main().doit(1); + System.out.println("passed"); + } +} |