Java中的感叹号是什么意思? [英] What does an exclamation mark mean in Java?

查看:41
本文介绍了Java中的感叹号是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在控制语句中的布尔表达式表示相反之前确认!=的含义:

I'd like to confirm the meaning of != before a boolean expression in a control statement means the opposite:

例如:

if (!networkConnected()) 

这是否意味着如果网络未连接"?

Does that mean "if the network is not connected"?

推荐答案

是的,它的逻辑正好相反.它甚至适用于 equals 运算符.

Yes it does mean the logical opposite. It works even with equals operator.

假设你的方法返回一个基本的 bool 类型

Assuming your method return a basic bool type

// means the Network is NOT connected
if (!NetworkConnected()) 

这相当于

if (NetworkConnected() != true) 

逻辑上的意思

if (NetworkConnected() == false) 

现在假设你的方法返回一个布尔值(确实是一个真实的对象),这意味着

Now assuming you method return a Boolean (indeed a real object), this means

// means the Network is NOT connected
if (! Boolean.TRUE.equals(NetworkConnected());

if (Boolean.FALSE.equals(NetworkConnected());

这篇关于Java中的感叹号是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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