I just started learning Java streams, and I have a question. Something that confuses me a lot is the following:
I just checked out the AutoCloseable
interface and it holds the close()
method.
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.
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.
Also, the abstract class AbstractPipeline
implements the BaseStream
interface and it provides an implementation of the close()
method.
Here is a diagram of the previously described:
List<String> stringList = new ArrayList<>();
Stream<String> stringStream = stringList.stream();
stringStream.close();
When I hold the ctrl keyboard key and 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 on 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?
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.
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.
Thanks to everyone that participated and helped me find the answer. Cheers!