简体   繁体   English

Apache下commons-lang工具包下BooleanUtils类的xor(true, true, true)结果为false,为什么?

[英]The result of xor(true, true, true) of the BooleanUtils class under the commons-lang toolkit under Apache is false, why?

The result of xor(true, true, true) of the BooleanUtils class under the commons-lang toolkit under Apache is false , but the result of System.out.println(true ^ true ^ true) is true . Apache下commons-lang工具包下BooleanUtils类的xor(true, true, true)结果为false ,而System.out.println(true ^ true ^ true)的结果true Why?为什么?

    public class Test {
    public static void main(String[] args) {
        System.out.println(org.apache.commons.lang.BooleanUtils.xor(new boolean[]{true, true, true}));
        System.out.println(org.apache.commons.lang3.BooleanUtils.xor(new boolean[]{true, true, true}));
        System.out.println(true ^ true ^ true);
    }
}
/*
    打印结果:
        false
        false
        true
 */

The most likely reason you are seeing this behavior is that you are using an older version of commons-lang (< 3.2).您看到此行为的最可能原因是您使用的是旧版本的 commons-lang (< 3.2)。

Newer versions behave the same as Java (ie it evaluates one xor at a time from left to right).较新版本的行为与 Java 相同(即从左到右一次计算一个异或)。

The older versions used a different approach however: They return true only if there is exactly one true value in the entire array.然而,旧版本使用了一种不同的方法:只有当整个数组中只有一个真值时,它们才返回真值。

This behavior was considered incorrect (see LANG-921 ) and has since been fixed.此行为被认为是不正确的(请参阅LANG-921 )并已修复。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尽管pom中包含commons-lang,但仍获取异常java.lang.NoSuchMethodError:org.apache.commons.lang.StringUtils.join - Despite having commons-lang included in pom, getting exception java.lang.NoSuchMethodError:org.apache.commons.lang.StringUtils.join Apache commons-lang StrBuilder与Java land StringBuilder有什么区别? - What is the difference between Apache commons-lang StrBuilder vs Java land StringBuilder? 为什么Java标准API中没有commons-lang? - Why isn't commons-lang in the java Standard API? 如何在commons-lang中使用ToStringBuilder设置toString方法的格式? - How do I set the format of toString methods with ToStringBuilder in commons-lang? Apache Commons Lang:从2.3升级到3.3.1 - UnhandledException怎么样? - Apache Commons Lang: Upgrade from 2.3 to 3.3.1 - What about UnhandledException Apache Commons Lang:&#39;lang&#39;和&#39;lang3&#39;之间的“不兼容性”会导致不同的运行时结果吗? - Apache Commons Lang: Can the “incompatibilities” between 'lang' and 'lang3' cause different runtime results? Apache Commons Lang HashCodeBuilder冲突 - Apache Commons Lang HashCodeBuilder collision 如何将commons-lang src安装到本地存储库? - How to install commons-lang src to local repository? Apache lang3有效,但Apache lang无效。 为什么? - Apache lang3 works but Apache lang does not. Why? 为什么 apache commons lang 是“lang”,lang 代表语言吗? - Why apache commons lang is "lang", does lang stand for language?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM