Return value of assignment operation in Java

故事扮演 提交于 2019-11-26 16:42:58

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.

Assignment expressions are evaluated to their assignment value.

(test = read.readLine())

>>

(test = <<return value>>)

>>

<<return value>>

(line = reader.readLine()) != null

means

  1. the method readLine() is invoked.
  2. the result is assigned to variable line,
  3. the new value of line will be proof against null

maybe many operations at once...

reader.readLine() reads and returns a line for you. Here, you assigned whatever returned from that to line and check if the line variable is null or not.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!