[英]Eclipse Java Stream Cast Issue
所有,
我有以下幾行代碼。
List<String> nodeList = Stream.of(nodes.split(","))
.map(String::trim)
.collect(Collectors.toList());
這使用gradle進行編譯。 但是,當它運行時,它會給出以下異常。
Unresolved compilation problem:
Type mismatch: cannot convert from List<Object> to List<String>
我不確定還可以提供什么,請詢問,我會答復。
我認為您會收到編譯時錯誤,因為項目屬性中的編譯器版本不匹配。 可能是您選擇了較低版本,然后該功能才存在於version(1.8)中 。
您需要檢查並確保以下內容:
轉到項目屬性
確保在Java構建路徑中選擇了適當的JDK 。 例如JDK 1.8 。
確保必須在項目屬性的Java Compiler下選擇適當的編譯器版本。 例如1.8
或者您可以直接在gradle文件中添加compileOptions
compileOptions
{
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_1_8
}
在我使用JDK8進行編譯的機器上,它運行良好。 嘗試將compileOption添加到gradle中,以確保您使用的是jdk8或更高版本,例如:
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
好,大家
為了使三葉草支持,我在gradle中添加了以下幾行。
eclipse.project {
natures "org.openclover.eclipse.core.clovernature"
buildCommands.clear()
buildCommand "org.openclover.eclipse.core.prejavabuilder"
buildCommand "org.eclipse.jdt.core.javabuilder"
buildCommand "org.openclover.eclipse.core.postjavabuilder"
}
刪除它們可以解決問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.