6
功能界面我有一個功能接口如何創建lambda表達式具有通用方法
@FunctionalInterface
interface MyInterface {
<T> T modify(Object);
}
我能爲這個接口
MyInterface obj = new MyInterface(){
@Override
<T> T modify(Object obj){
return (T) obj
}
}
如何爲此創造lambda表達式創建匿名類。
MyInterface obj -> {return (T) obj;}; // ! ERROR as T is undefined
檢查這個問題:
@FunctionalInterface interface MyInterface<T> { T modify(Object obj); }
然後按如下方式使用它http://stackoverflow.com/q/22588518/1679863 –
因子的拉姆達成的方法,以及使用方法參考。 –