Welcome to this Blog. I am Software Engineer and work for Zühlke Engineering AG in Bern. This is my private blog, in which I will post mainly about technical stuff like Software Engineering or IT related topics. The views expressed herein do not necessarily represent those of my employer.

 

 
 

 

Today, I encountered a very helpful feature in Eclipse. When I am debugging code, I sometimes want to know, what’s the result of a method is. If the result it’s not assigned to a variable, it gets complicated. Take a look to this example: what is the result of add(17,19)?

public class DemoApplication {
 
    public static void main(String[] args) throws Exception {
        DemoApplication calc = new DemoApplication();
        System.out.println(calc.divide(calc.add(17, 19), 2));
    }
 
    public int add(int i, int j) {
        return i + j;
    }
 
    public int divide(int i, int j) {
        return i / j;
    }
}

In earlier times, I stepped one step further to get into the method divide. Then I got the result of add(17,19) in my parameter.

 

But Eclipse is offering a better solution. In the Debugging Perspective, there is a view called Expressions. Just add a new expression add(17,19) and the Debugger is printing out the result.

image

The result is directly printed out:

image

 

A simple, but helpful feature in Eclipse!

 

 

 

 

 
  1. There’s an even easier way: while debugging, select the expression ‘calc.add(17, 19)’ and hit Ctrl+Shift+D (Display) or Ctrl+Shift+I (Inspect). Both will show the result of the selected expression. While Display will only show the toString() of the result, Inspect will let you drill down the object graph and inspect each member of the resulting object.

    You can add the current selection to the Expressions view as well by right-clicking and selecting the menu item Watch.

    Comment by Philip — 13.12.2008 @ 13:15

Leave a comment