In Intellij 15.0.3。並使用Java8我在使用::new
時遇到問題。 特別是,我有一個類有一個默認的構造Java8報告「無法通過調用」:: new「解析構造函數」
public class Container{
public Container(){}
}
我想創建一個列表中的地圖,如下所示:
public class Test{
private final Map<Key, Container> map;
@Before
public void setUp(){
List<Key> keys=...//Init the list
map = keys.stream().collect(Collectors.toMap(Function.identity(), Container::new));
}
}
在的IntelliJ,new
爲紅色,提示說:cannot resolve constructor Container
如果我做() -> {new Container()}
我也有cannot infer functional interface type Container
任何想法,爲什麼?
'toMap'有兩個參數。第一個是_keyMapper_(所以我有'Function.identity()',第二個是_valueMapper_,它必須返回一個新的'Container'類的實例,你正在反轉鍵和值 –
正是你想要的沒有道理 – NimChimpsky