简体   繁体   English

Android是否执行布尔短路?

[英]Does Android perform boolean short-circuiting?

I know that Java performs optimization for double ampersands in boolean expressions, such as 我知道Java对布尔表达式中的双与号进行优化,例如

if(a && b)

If a is false, b is not evaluated. 如果a为假,则不评估b。 Does this apply to the Android platform? 这是否适用于Android平台?

This is a Java language rule and is converted by the compiler into appropriate Java bytecode. 这是Java语言规则,由编译器转换为适当的Java字节码。 The Dalvik toolset then converts the bytecode into .dex files. 然后Dalvik工具集将字节码转换为.dex文件。 Therefore, the Java system will apply the short-circuiting appropriately before the Android system even processes the code. 因此,Java系统将在Android系统甚至处理代码之前适当地应用短路。

It doesn't have any choice. 它别无选择。 It is required to do so by the Java Language Specification #15.23 . Java语言规范#15.23要求这样做。

Yes, Android uses Java for its platform. 是的,Android将Java用于其平台。 It is a language rule in Java, and so it is in Android 这是Java中的语言规则,因此在Android中也是

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM