Intellij IDEA Contract 误报语法错误

问题描述

虽然我做对了,但还是出现了错误(我认为)

@Contract("!null -> !null,_,_; null -> null,_")
public <T> T deserialize(@Nullable final Object object,@Nullable final GenericDeclaration genericSource,@NotNull final Class<T> targetClass,@Nullable final GenericDeclaration genericTarget) {

基本上,我试图创建一个合同,如果第一个参数为空则返回空,否则不为空。但我不想在合约中添加其他参数,或者只是用 _ 键忽略它。

Intellij IDEA 版本为 2021.1.2(最新版本)

它抱怨返回值,我不知道为什么?

yellow error

解决方法

@Contract("!null,_,_ -> !null; null,_ -> null");

我猜。参数列表 -> 结果; ...见Syntax