This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi, after going through various code and APIs, one problem lead to another and right now I'm so confused that I'm not even sure if this is the right question!
I was given some sample code based on JDOM to work on XML files. It uses the collection framework which I am not familiar with (I was taught with JDK 1.4). In these sample codes (and many tutorials), I noticed many instances where an interface reference type invoked an interface method, yet I was unable to track down exactly which class implemented that interface.
In my n00b understanding, an interface method must be overridden somewhere! It does not make sense to use an abstract method. It is very frustrating and confusing to not be able to find that hidden class. Here is the code snippet in question:
You can find out the actual name of the concrete class by calling getClass().getName() on an instance of the class. But in general, it doesn't really matter. The purpose of the interface is to abstract away the need to depend on particular concrete classes, your code only depends on the interface that that class implements. The actual concrete class could some well-known public class, a private class, or even an anonymous class. It doesn't really matter, You know what methods you can call because you know what interface the object implements.
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter