简体   繁体   English

Eclipse Java Stream Cast问题

[英]Eclipse Java Stream Cast Issue

All, 所有,

I have the following lines of code. 我有以下几行代码。

List<String> nodeList = Stream.of(nodes.split(","))
      .map(String::trim)
      .collect(Collectors.toList());

this compiles using gradle. 这使用gradle进行编译。 But when it runs, it gives the following exception. 但是,当它运行时,它会给出以下异常。

Unresolved compilation problem:
Type mismatch: cannot convert from List<Object> to List<String>

I'm not sure what else to provide, ask and I will respond. 我不确定还可以提供什么,请询问,我会答复。

I think you are getting compile time error because there is a mismatch in compiler version in project properties. 我认为您会收到编译时错误,因为项目属性中的编译器版本不匹配。 May be you selected lower version then the feature exist in version(1.8) . 可能是您选择了较低版本,然后该功能才存在于version(1.8)中

You need to check and make sure for below: 您需要检查并确保以下内容:

Go to project properties 转到项目属性

  1. Make sure appropriate JDK has been selected in Java Build Path. 确保在Java构建路径中选择了适当的JDK eg JDK 1.8 in this case. 例如JDK 1.8

  2. Make sure appropriate compiler version must be selected under Java Compiler in project properties. 确保必须在项目属性的Java Compiler下选择适当的编译器版本。 eg 1.8 例如1.8

Or you can directly add compileOptions in your gradle file 或者您可以直接在gradle文件中添加compileOptions

compileOptions 
{  
     targetCompatibility JavaVersion.VERSION_1_8  
     sourceCompatibility JavaVersion.VERSION_1_8  
}

It works fine on my machine which is using JDK8 to compile it. 在我使用JDK8进行编译的机器上,它运行良好。 Try to add the compileOption to your gradle to make sure you are using jdk8 or above like : 尝试将compileOption添加到gradle中,以确保您使用的是jdk8或更高版本,例如:

compileOptions {  
sourceCompatibility JavaVersion.VERSION_1_8  
targetCompatibility JavaVersion.VERSION_1_8  
}

Ok, everyone. 好,大家

I had added the following lines to gradle in order to enable clover support. 为了使三叶草支持,我在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"
}

Removing them fixed the problem. 删除它们可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM