Home > Back-end >  Newbie question: in the LinkedList getFirst () method, the final modifier
Newbie question: in the LinkedList getFirst () method, the final modifier

Time:01-01

Could you tell me the getFirst LinkedList () method of the variable inside f: why do you want to use the final modification?



CodePudding user response:

I don't know what you see is what version of the JDK source code?
Why is the source of my here like this:
 
Public E getFirst () {
If (size==0)
Throw new NoSuchElementException ();

The return header. Next. Element;
}

CodePudding user response:

reference 1st floor sunyiz response:
don't know what you see is what version of the JDK source?
Why is the source of my here like this:
 
Public E getFirst () {
If (size==0)
Throw new NoSuchElementException ();

The return header. Next. Element;
}

8 u231

CodePudding user response:

refer to the second floor 枠 generic response:
8 u231


May be written before the code,
Is to use this reference in any anonymous inner class, then deleted
After the references of final mark didn't remove
After all, the JDK source code is written
From this the only way for the current implementation of the
I don't think there are no need to use the final modified
Even without the local reference statement necessary
With "first" can be directly
Because it only refer to its properties, and didn't change its properties
Even the thread safety problem does not exist

CodePudding user response:

reference sunyiz reply: 3/f
Quote: refer to the second floor 枠 generic response:

8 u231


May be written before the code,
Is to use this reference in any anonymous inner class, then deleted
After the references of final mark didn't remove
After all, the JDK source code is written
From this the only way for the current implementation of the
I don't think there are no need to use the final modified
Even without the local reference statement necessary
With "first" can be directly
Because it only refer to its properties, and didn't change its properties
Don't even exist the problem of thread safety

Ok, thanks a lot
  • Related