I’m doing this as part of a Java tutorial, so it is probably not very hard to answer at all — I am very stuck, though, so thanks for any help!
I have the following problem: I have an interface a, and a library I downloaded as part of the tutorial which takes an (implemented) interface of type a and displays it in a GUI. The trouble is that it does not compile; eclipse says I must cast it. When I do, it compiles, but gives me a casting error.
The strange thing is that both interfaces have exactly the same code. In fact, I copied and pasted the library’s one over mine, and it still does not work.
How can it be that the two interfaces have the same code but I can’t cast? What is wrong with my implementation of the interface?
If you need any additional information, please tell me!
You cannot cast between two unrelated interfaces, no matter whether their definition is identical or not. The language simply does not allow that. Two distinct interface declarations, even if they are identical, result in two distinct interfaces.
You need to change your design so that you only have a single interface and all clients and implementers of the interface refer to the same single interface.