Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a close() method invoked from Stream point to the implementation of the close() method in the AbstractPipeline abstract class?

I just started learning Java Streams, and I have a question. Something that confuses me a lot is the following:

  1. I just checked out the AutoCloseable interface and it holds the close() method.

  2. The BaseStream interface extends the AutoCloseable interface, and the rule of inheritance supplies, meaning that the close() method can be used from the BaseStream interface.

  3. The Stream interface extends the BaseStream interface, and the rule of inheritance supplies, meaning that the close() method can be used from the Stream interface.

  4. Also, the abstract class AbstractPipeline implements the BaseStream interface and it provides an implementation of the close() method.

This is the diagram of the previously described.

List<String> stringList = new ArrayList<>();
Stream<String> stringStream = stringList.stream();
stringStream.close();

When I hold the Ctrl keyboard button and click left click on the mouse it points me to the abstraction of the close() method in the BaseStream interface, but when I press Ctrl+Alt+B it points me to the implementation of the method in the AbstractPipeline abstract class.

The question is:

How can a close() method that is invoked of Stream point me to the implementation of the close() method in the AbstractPipeline abstract class, when Stream and AbstractPipeline do not interact and their main connection is the BaseStream?

Is this some kind of object oriented concept that i'm not aware of?

Thank you.

Update:

I'm using IntelliJ IDEA 2020.1.2 (Ultimate edition) and JDK 1.8 but I've also tried it with JDK 14 and Eclipse IDE for Enterprise Java Developers version 2019-06 (4.12.0) and it is the same.

like image 366
stack overflow Avatar asked Jul 02 '20 15:07

stack overflow


1 Answers

There is an abstract class ReferencePipeline which extends abstract class AbstractPipeline and implements Stream, but isn't overriding the close() method. This abstract class is the connection and the answer I was looking for. Now, everything seams reasonable and is clear for me. Here is the full diagram, which clears the answer to this question.

enter image description here

Thanks to everyone that participated and helped me find the answer. Cheers!

like image 83
stack overflow Avatar answered Oct 24 '22 11:10

stack overflow