Can I find out from which class a given method’s implementation is inherited? e.g. in the current object, which toString() implementation is used, from Object class, or some other parent class?
Can I find out from which class a given method’s implementation is inherited? e.g.
Share
Try
Method.getDeclaringClass()(link to 1.5 API)Note that you cannot know if the implementing class only calls the
super:To determine the class from which the method is inherited you would need to:
Example:
Outputs:
I noticed from the question that you wanted to get super class that overrides the method if available. Here is a demo: