简体   繁体   中英

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. 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) .

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. eg JDK 1.8 in this case.

  2. Make sure appropriate compiler version must be selected under Java Compiler in project properties. eg 1.8

Or you can directly add compileOptions in your gradle file

compileOptions 
{  
     targetCompatibility JavaVersion.VERSION_1_8  
     sourceCompatibility JavaVersion.VERSION_1_8  
}

It works fine on my machine which is using JDK8 to compile it. Try to add the compileOption to your gradle to make sure you are using jdk8 or above like :

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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