mybatis中resolveGetterConflicts()方法中这段代码如何解释?为什么布尔值不同于其他 class?

How to explain this code in resolveGetterConflicts() method in mybatis? why boolean is different from other class?

private void resolveGetterConflicts(Map<String, List<Method>> conflictingGetters) {
for (Entry<String, List<Method>> entry : conflictingGetters.entrySet()) {
  Method winner = null;
  String propName = entry.getKey();
  for (Method candidate : entry.getValue()) {
    if (winner == null) {
      winner = candidate;
      continue;
    }
    Class<?> winnerType = winner.getReturnType();
    Class<?> candidateType = candidate.getReturnType();
    if (candidateType.equals(winnerType)) {
      if (!boolean.class.equals(candidateType)) {
        throw new ReflectionException(
            "Illegal overloaded getter method with ambiguous type for property "
                + propName + " in class " + winner.getDeclaringClass()
                + ". This breaks the JavaBeans specification and can cause unpredictable results.");
      } else if (candidate.getName().startsWith("is")) {
        winner = candidate;
      }
    } else if (candidateType.isAssignableFrom(winnerType)) {
      // OK getter type is descendant
    } else if (winnerType.isAssignableFrom(candidateType)) {
      winner = candidate;
    } else {
      throw new ReflectionException(
          "Illegal overloaded getter method with ambiguous type for property "
              + propName + " in class " + winner.getDeclaringClass()
              + ". This breaks the JavaBeans specification and can cause unpredictable results.");
    }
  }
  addGetMethod(propName, winner);
}
}

在我看来,subclass 中的重写方法可能 return 类型的子类型 return 由 superclass 中的重写方法编辑,上面的方法可以解决这种情况。

但是,我对方法中的这些代码很困惑:

      if (!boolean.class.equals(candidateType)) {
        throw new ReflectionException(
            "Illegal overloaded getter method with ambiguous type for property "
                + propName + " in class " + winner.getDeclaringClass()
                + ". This breaks the JavaBeans specification and can cause unpredictable results.");
      } else if (candidate.getName().startsWith("is")) {
        winner = candidate;
      }

```

为什么布尔值与其他值不同 class?有人可以帮助我吗?谢谢!!

好的,因为 JavaBean 规范允许遵循:

public boolean isBool() {return true;}
public boolean getBool() {return false;}