提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
为功能接口创建内部类的实例
import java.util.function.Consumer; public class Main { public static void main(String[] args) {/**来自 时代Java**/ VariableAccessInner vai = new VariableAccessInner(); VariableAccessInner.InnerClass inner = vai.new InnerClass(); inner.lambdaInMethod("Hello"); } } class VariableAccessInner { String CLASSA = "Class-level A"; class InnerClass { String CLASSA = "Class-level B"; void lambdaInMethod(String passedIn) { String METHODA = "Method-level A"; // passedIn = "test"; Consumer<String> l1 = x -> { System.out.println(x); System.out.println("CLASSA Value: " + CLASSA);