What is the difference between call hierarchy and find references eclipse?

I got confused when using this two commands in eclipse Ctrl+Shift+G and Ctrl+Alt+H both are returning same results .

Scenario:

Want to find where the method "findUsage" has been called.

Sample Class

enter image description here

Call Hierarchy Output (Ctrl+Alt+H) .

enter image description here

Find References (Ctrl+Shift+G) output

enter image description here

Both are showing same results. Can anyone know what is the difference between these two commands?


Solution 1:

"Find references" shows you all direct callers of the selected method. "Call hierarchy" in contrast shows also the callers of those direct callers, and the callers of those, ... and so on.

So the output is only identical, if direct callers of your selected method do not have any callers themselfes. Just try both commands on some larger code base and you will immmediately see the difference, like in this screenshot:

Call hierarchy

If you wonder why there are two such features, if "Find references" is basically just a subset of the "Call hierarchy": Find references works really fast, so you can use it all the time without any waiting for results. The call hierarchy on the other hand takes more computation time and therefore may interrupt your coding workflow.

Solution 2:

  • Ctrl + Shift + G : Reference in workspace. It shows only references of selected class or method or variable in source code.
  • Ctrl + Alt + H : Call Hierarchy. It shows all hierarchy up to root class.