Java two equal signs in one statement?

Can someone help me figure out what the following code does and what a line with two equal signs does? How does something equal to something equal work in this constructor?

public More ...LinkedList() {
      header.next = header.previous = header;
 }

Here is a link to the site where I saw this, and I'm trying to figure it out: http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/util/LinkedList. java # LinkedList.0header

+4
source share
5 answers

Reading an assignment operation from right to left:

  • assign header header.pevious
  • assign header.previous header.next

Bottom line: after this line, both header.previous header.nextwill refer to header.

+8
source

= = . . header.next header.previous .

  • header.next = header.previous = header;

, ...

  • header.next = header;
  • header.previous = header;
+4

header.next header.previous header.

:

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

val1, val2 val3 , 10

+4

, header.next, header.previous header.

+3

As simple and similar to a = b = 10, the value 10 is assigned to the variable b (b = 10), and then the value of the variable b is assigned to the variable 10 (therefore a = 10). See here for more details .

+3
source

Source: https://habr.com/ru/post/1526034/


All Articles