2016-11-13 19 views

回答

0

是的,这是可能的。
您可以将值复制到有效最终局部变量

class Main { 
    interface Test{ 
     String method(); 
    } 
    void w(){ 
     String str = "foo"; 
     str = "bar"; 
     String tmpStr = str; 
     Test t =() -> tmpStr; 
    } 
} 

由于现在临时值有效最终,您可以在lambda表达式或匿名类使用它。

相关问题