ReflectionHelper :: assertGetterMethod()与构造启发式要求冲突

时间:2019-06-11 01:56:37

标签: optaplanner

我有以下内容:

@CustomShadowVariable(variableListenerRef = @PlanningVariableReference(variableName = "..."))
@Override
public boolean isXyz() {
    return xyz;
}

然后我得到以下信息:

java.lang.IllegalStateException: The entityClass (class ...) has a PlanningVariable annotated member (bean property ... on class ...) that returns a primitive type (boolean). This means it cannot represent an uninitialized variable as null and the Construction Heuristics think it's already initialized.
Maybe let the member (...) return its primitive wrapper type instead.

...看到我真的会将boolean更改为Boolean,但是我会得到以下信息:

java.lang.IllegalStateException: The getterMethod (public java.lang.Boolean isXyz()) with a CustomShadowVariable annotation must have a primitive boolean return type (class java.lang.Boolean) or use another prefix in its methodName (isXyz).

似乎构造启发式方法想要一个可为空的类型,以便它可以具有一个为空的初始化值,但是当提供一个布尔对象时,反射助手断言会尝试针对失败的原始类型进行验证。

这是缺陷吗?

1 个答案:

答案 0 :(得分:1)

将方法名称更改为getXyz(完整签名:Boolean getXyz())。

我只是猜测,因为我手头没有一个包含此类shadow变量的示例域。但是看看ReflectionHelper代码,这可能就是解决方案。如果可行,我将尝试改进异常消息。