Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java two equal signs in one statement? [duplicate]

Can someone help me understand what the following code does and what the line with two equal sign does? How does something equal to something equal to something work in this constructor?

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

Here is the link to the website 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

like image 655
Hell Man Avatar asked Feb 09 '14 15:02

Hell Man


1 Answers

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.

like image 106
AlexR Avatar answered Sep 19 '22 19:09

AlexR