简体   繁体   English

条件(==)检查如何在 JAVA 中工作?

[英]How condition(==) check works in JAVA?

can someone explains how this line works in JAVA?有人可以解释这条线在 JAVA 中的工作原理吗?

boolean result = value == null

It evaluates value == null , and assigns true or false to result .它评估value == null ,并将 true 或 false 分配给result

Due to the evaluation order, you don't need parentheses result = (value == null) .由于评估顺序,您不需要括号result = (value == null)

boolean result = value == null

means you declare a boolean variable result and assigning it to the return value of value == null意味着您声明一个 boolean 变量result并将其分配给value == null的返回值

  1. value == null --> ture or false value == null --> 真或假
  2. boolean result = true|false boolean 结果 = 真|假

Java will compare the value with null first, after matching both the values then resulting value will be assign as true or false to the result variable. Java 将首先将值与 null 进行比较,在匹配这两个值之后,结果值将被分配为 true 或 false 给结果变量。 it will check also for data type(if needed, like you cant compare boolean values with null).它还将检查数据类型(如果需要,就像您无法将 boolean 值与 null 进行比较)。

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

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