使用gradle和IntellJ IDEA构建时,我得到了不同的构建结果。用gradle编译时出现错误,使用IntelliJ编译时有效。
以下代码段是有问题的:
fun getFieldValuesByCollection(databaseName: String, collectionName: String, fieldName: String): List<String> {
return dbHelperService
.getCollectionFromDb(databaseName, collectionName)
.find()
.map<String> {
doc -> doc.getString(fieldName)
}.toList()
}
问题在于地图功能。
当删除带有lambda函数的map-call时,不会导致构建错误。
这是gradle的错误
> Task :compileJava FAILED
error: cannot access getFieldValuesByCollection$1
bad class file: /Users/******/monitoring/service/UserStatisticsService$getFieldValuesByCollection$1.class
undeclared type variable: U
Please remove or make sure it appears in the correct subdirectory of the classpath.
Env: gradleVersion ='4.10.2', JREVersion ='1.8'