在java中返回赋值操作的值 [英] Return value of assignment operation in java

查看:313
本文介绍了在java中返回赋值操作的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  while((line = reader.readLine())!= null){
out.append(line);
}

分配操作如何在Java中返回值?正如我们正在检查的语句是 line = reader.readLine()并将其与 null 进行比较。因为 readLine 将返回字符串,我们正在检查 null

解决方案

Java中的赋值运算符返回分配的值(例如,在 c )。所以这里, readLine()将被执行,它的返回值存储在中。然后根据 null 检查该值,如果是 null ,则循环将终止。


I encountered a statement in java

while ((line = reader.readLine()) != null) {
    out.append(line);
}

How assignment operations return value in Java? As the statement we are checking is line=reader.readLine() and comparing it with null. Because readLine will return string , how exactly we are checking for null?

解决方案

The assignment operator in Java returns the assigned value (like it does, e.g., in ). So here, readLine() will be executed, and it's return value stored in line. That value is then checked against null, and if it is null, the loop will terminate.

这篇关于在java中返回赋值操作的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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