I've got a class which overrides equals() and I want to see where this equals method is being used in the workspace. Using Eclipse, I generally do Ctrl-Shift-g which finds all references in the workspace. Unfortunately, for equals(), its pulling back every single reference of equals in my workspace from any type, not just the one where I've overridden it and its impossible to figure out which of the many results is pertinent to my search. Is what I want to do possible?
EDIT: To clarify. I have a class A which overrides the equals method. I have开发者_如何学C a class B (and others) which use class A but do not extend it. I want to find which classes in my workspace use Class A's equals method regardless of whether or not they belong to Class A's hierarchy such as Class B.
Let your equals implementation temporarily throw the class Throwable: equals(Object obj) throws Throwable
.
Of course this will give you a compile error on your equals implementation because it is not compatible with Objects.equals()
, however you will also get a compile error in all classes which are using your equals method (at least all classes which do not handle/throw Throwable themselves):
Unhandled exception type Throwable
In general you can't do this as equals is on Object, take for example
mysession.getAttribute("someobject").equals(foo)
no way to detect that this object is your class type.
Create copies of main interface, class with a diffrent name. Implement/Extend from these new interface/class. Then search for references of your method with Ctrl+Shift+G.
Worked for me, when faced with same situation.
Right click on your equals method and select the option
References--> Hierarchy
精彩评论