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.
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.
close()
will be that ofAbstractPipeline
, but however, this is either an feature or bug or IntelliJ (or whatever IDE you use) and has nothing to do with Java or any OOP Concept – Loquacityclose()
method; where do you land? – CaliaAbstractPipeline
, implementingStream
, but not overriding the inheritedclose()
method. Perhaps, there is more than one class with these properties, but the debugger should show you which actual class you encountered when stepping into the invocation of theclose()
method. I’m not sure, what problem you have with this concept. Your IDE is capable of jumping to this particular implementation method even at compile-time, because it has scanned the environment and found that all implementation classes have these properties, so thatclose()
is the only one. – Calia