how to compare two methods in eclipse

强颜欢笑 提交于 2019-12-06 17:43:23

问题


I want to compare two methods that I think are the same, but the eclipse refactor won't make extract method from their content together.

Can I compare the two of the them using eclipse compare?

  • the methods are of the same class.

回答1:


I'm using Eclipse Kepler, so depending on your version your mileage may vary.

To compare two methods in the same class, do the following:

  1. Open the class.
  2. Show the Outline view (Window->Show View->Outline)
  3. Hold CTRL and click on the two methods you wish to compare.
  4. Right click on one of the highlighted methods.
  5. Click on "Compare With->Each Other By Member"

You'll get a diff window similar to if you were comparing two files.

Update

Since answering this question, I have found a similar, but more powerful way to do this. Follow the steps above, except use the "Package Explorer" view rather than the outline view. The advantage of this is that you can choose to compare two methods that are in the same class or compare two methods that are in different classes. It's a great way to prove that two methods or subclasses are identical and can be refactored into a common shared resource.




回答2:


May be you can put the two methods in different class file, and put them in Eclipse together. Then simply select them in the navigator or package explorer, right click, and click 'Compare with Each Other'.

Or you can check this question: Diff two methods in eclipse




回答3:


An illustration might make it easier to follow the instructions in this answer and this answer:



来源:https://stackoverflow.com/questions/8708367/how-to-compare-two-methods-in-eclipse

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!