I'm reading LinkedBlockingQueue code (JDK8u), and I find LinkedBlockingQueue's head field is not private, but last field is private. I can't find any particular opration with head . So why not set head to private ?
/**
* Head of linked list.
* Invariant: head.item == null
*/
transient Node<E> head;
/**
* Tail of linked list.
* Invariant: last.next == null
*/
private transient Node<E> last;
I examined the
LinkedBlockingQueue.javafile in thejdk7usource code and saw that both fields (head,last) are naturally defined as hidden. This is a commonly used technique in programming languages based on OOP to prevent direct client access to fields. Relevant lines of code are available below:Coming to your question, it's possible that you come across different uses when browsing from a different source. However, you are always responsible for questioning and investigating its reliability. I recommend looking at more sources to get good code practices.