Java two equal signs in one statement? [duplicate]

拜拜、爱过 提交于 2019-12-01 18:19:55

Read assignment statement from right to left:

  1. assign header to header.pevious
  2. assign header.previous to header.next

The bottom line: after this line both header.previous header.next will refer to header.

header.next and header.previous have same value of header.

Example:

int val1 = 10;
int val2 = 11;
int val3 = val2 = val1;

Here At last val1,val2 & val3 has the same value as 10

A single = is the assignment operator. This is a way to do multiple assignment in one line of code. It is setting header.next and header.previous to the value of header.

  1. header.next = header.previous = header;

Is the same as...

  1. header.next = header;
  2. header.previous = header;

This means both header.next and header.previous will be set to header.

Its as simple and as similar as a = b = 10 were value 10 is assign to variable b (b=10) and then value of variable b is assign to variable 10 (therefore a = 10). Please see here for more details.

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