[英]Incompatible types error using lombok.Getter(lazy = true) with java 10
我试图做一些使用缓存reactor
, reactor.ipc.netty.http.client.HttpClient
并初始化它与龙目岛的懒惰吸气场@Getter(lazy = true)
在 Java 8 中一切正常,但无法编译并error: incompatible types: Duration cannot be converted to String
此代码段上的 Java 10 error: incompatible types: Duration cannot be converted to String
@Value
public static class Translations {
Map<String, Translation> translations;
@Value
public static class Translation {
Map<String, String> content;
}
}
@Getter(lazy = true)
Mono<Map<String, Translations.Translation>> translations = httpClient
.get(String.format("%s/translations/%s", endpoint, translationGroup), Function.identity())
.flatMap(it -> it.receive().aggregate().asByteArray())
.map(byteArray -> {
try {
return objectMapper.readValue(byteArray, Translations.class);
} catch (IOException e) {
throw new UncheckedIOException("Failed to get translation for " + translationGroup, e);
}
})
.map(Translations::getTranslations)
.retryWhen(it -> it.delayElements(Duration.ofMillis(200)))
.cache(Duration.ofMinutes(5))
.timeout(Duration.ofSeconds(10));
但它编译得很好
@Getter(lazy = true)
Mono<Map<String, Translations.Translation>> translations = Mono.just(new byte[]{})
.map(byteArray -> {
try {
return objectMapper.readValue(byteArray, Translations.class);
} catch (IOException e) {
throw new UncheckedIOException("Failed to get translation for " + translationGroup, e);
}
})
.map(Translations::getTranslations)
.retryWhen(it -> it.delayElements(Duration.ofMillis(200)))
.cache(Duration.ofMinutes(5))
.timeout(Duration.ofSeconds(10));
如何知道出了什么问题以及如何解决?
我建议将初始化代码移到单独的方法中。
@Getter(lazy=true)
SomeType t = <complicatedInitializationCode>;
变成
@Getter(lazy=true)
SomeType t = initializeT();
private SomeType initializeT() {
return <complicatedInitializationCode>;
}
披露:我是龙目岛的开发人员。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.