=和== If语句中的差异Java [英] = and == difference in If statement Java

查看:103
本文介绍了=和== If语句中的差异Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里面对一些奇怪的事情。如果我遗失了什么,请帮助我理解。我的if条件应该是:

I am facing something strange here. Please help me understand if I am missing something. My if condition was supposed to be:

if(configuredPdf == true)

但是我写错了:

if(configuredPdf = true)

我的Eclipse编译器不会要求我更正它。然后我假设没有编译时间或检查异常。所以:

And my Eclipse compiler does not ask me to correct it. Then I assume there is no compile time or checked exception. So:

(configuredPdf = true)

返回布尔值?

推荐答案

是, configuredPdf = true 为您的变量分配 true 并返回 true 。因此, if(configuredPdf = true)是一个有效的语法,即使它通常是一个错误。

Yes, configuredPdf = true assigns true to your variable and returns true. Therefore if (configuredPdf = true) is a valid syntax even though it's usually a bug.

使用起来更安全 if(configuredPdf)以避免这种拼写错误。

It's safer to use if (configuredPdf) to avoid this kind of typo.

这篇关于=和== If语句中的差异Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆