When java calls methods through interfaces, how do you know which implementation class is in the calling class.

92 5

An abstract interface, with many implementation classes, when calling a method through an interface, how to know which implementation class is called?

Thank you.

2014-07-02 update

And the first three answers are 可以, but I still haven't found the answer I want. For example, looking at someone else 's in Eclipse, it's possible to see the source of the method in the interface if you go directly to the source by pressing ctrl, and?

5 Answers

60 3

Get its class with an object 's getClass() method, and then you'll be able to determine which implementation class this is.

Polymorphism is the concept of runtime, and it isn't possible to know exactly which implementation to use before running. What you can do is find all the classes that implement this interface and then guess what's going on.