开发者

Compare 2 objects in eclipse in runtime (while debugging)?

Can I compare 2 Objects using the Eclipse - Expressions tool, am trying to debug a Java program. The max I can do is, add both the objects to Expressions and manually expand the object to compare, I wish there was like, select 2 Object (of same kind - 开发者_JAVA百科Class, Of course) and say "Compare" and Eclipse parses both the objects and highlights all the differences..

PS: I'm not lazy to do this manually, its just that the Object I'm dealing with is very complicated, like its got 10 levels or arraylist of Objects :)


Not a elegant solution but it has worked well for me in the past is to include something like gson or other json parser in your classpath. Then in the Display view type:

new Gson().gson.toJson(yourObject1)  

and

new Gson().gson.toJson(yourObject2)

Then use the json ouput save it to files and use a file comparison tool. Longwinded but with complex objects its often worth it.


They can be as detailed or simple as you want them to be. Using a equals expression in the Display view may tel you if two objects are the same, but if their different, it won't tell you what those differences are. Consider using Eclipse detail formatters. They are awesome.

Eclipse's Inspect view can often be littered with unwanted data that just clutters your mind and what your really interested in. The ouput you decide to display is your choice with detail formatters.

See the link below for an idea of how to use them.

http://www.howardism.org/Technical/Eclipse/Eclipse_Detail_Formatter.html


Find "Display" view under debug category. It is not open by default in the java debug perspective. You will be able to execute pretty much arbitrary java statements during the debug session.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜