我正在用神奇的 vavr 库(0.9.2)弄脏我的手。
这是一个代码片段,旨在收集Either:
Either<Tuple2<Enum<ReportByTeamExecutionErrors>,String>, List<MayurDAO>> payloadPreparationResult =
new ReportByTeamCriteriaSchemaChecker("./json/schema/REQ_ReportByTeam_Schema.json")
.validateSchema(payLoad) // payload is JSON and is a paramter to this holding function
.map(JsonPOJOBidirectionalConverter::pojofyCriteriaAllFieldsTeam)
.map((e) -> {
CriteriaTeamAllFieldsValidator validator = new CriteriaTeamAllFieldsValidator(e.right().get());
return(validator.validate());
})
.map((e) -> retrieveRecordsAsPerCriteria(e.right().get())) // compiler doesn't approve of this line!!
;
retrieveRecordsAsPerCriteria方法是这样定义的:
private Either<Tuple2<Enum<ReportByTeamExecutionErrors>,String>, List<MayurDAO>>
retrieveRecordsAsPerCriteria(CriteriaAllFieldsTeam criteriaAllFieldsTeam) {
Optional<List<MayurDAO>> retrievedRecords = new MayurModel().retrieveRecords(criteriaAllFieldsTeam);
return( (retrievedRecords.isPresent())
? (Either.right(retrievedRecords.get()))
: Either.left(
Tuple.of(
ReportByTeamExecutionErrors.NO_RECORDS_FOUND_TO_MATCH_CRITERIA,
"No records have been found, which match the criteria passed"
)
)
);
}
编译器抱怨:
./com/myApp/application/ReportByTeamResource.java:58:错误:不兼容的类型:无法推断类型变量 L、R .map((e) -> retrieveRecordsAsPerCriteria(e.right().get()) ); ^(实际参数列表和形式参数列表的长度不同)其中 L,R 是类型变量: L 扩展在方法 right(R) 中声明的对象 R 扩展在方法 right(R) 中声明的对象 1 错误
该列表来自 java.util.List。
我无法理解问题的根源。类型应该很容易推断,或者我认为。
直到这条令人反感的线之前,IntelliJ 似乎都可以接受转换!然而,在那一行中,类型参数 U 是不可破译的。由于某种原因,有人可以将我推到我看不到的路径吗?