xen*_*ide 1 java lambda filter java-8 java-stream
public class ActivityInventoryMem<Activity> extends TreeSet<Activity> implements ActivityInventory<Activity> {
@Override
public ToDo toDo( LocalDate date ) {
Stream<Activity> s = this.parallelStream();
s.filter( a -> a.completed() );
return new ToDo();
}
}
Run Code Online (Sandbox Code Playgroud)
这是例外
java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: java.util.stream.Stream.filter
at com.lm.infrastructure.memory.ActivityInventoryMem.toDo(ActivityInventoryMem.java:16)
at com.lm.infrastructure.memory.ActivityInventoryMemNGTest.testToDo(ActivityInventoryMemNGTest.java:46)
Run Code Online (Sandbox Code Playgroud)
我在jdk 8中运行它,我把以下内容放入我的内容中pom.xml,它现在似乎认出了lambda的
<!-- maven-compiler-plugin -->
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
Run Code Online (Sandbox Code Playgroud)
问题(从我从netbeans收集到的)是它a只是一个Object不是Activity因为它无法看到.completed(),我怎么能解决这个问题呢?
在你的声明中:
public class ActivityInventoryMem<Activity> extends TreeSet<Activity> implements ActivityInventory<Activity>
// ^ (1) ^ (2) ^ (3)
Run Code Online (Sandbox Code Playgroud)
的用途Activity在(2)和(3)如类型参数的TreeSet和ActivityInventory,而在(1)的声明一个使用新类型参数为你的ActivityInventoryMem类.因此,Activity在该类中使用符号并不是指您的实际Activity类,它们引用了一些实际类型未知的类型参数.
你可能只想在你的班级声明中留下(1):
public class ActivityInventoryMem extends TreeSet<Activity> implements ActivityInventory<Activity>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
350 次 |
| 最近记录: |