Can I find out the return value before returning while debugging in Eclipse?

Found a really good shortcut for this. Select the expression which returns the value and press

Ctrl + Shift + D

This will display the value of the return statement. This is really helpful in cases where you can't or don't want to change just for debugging purpose.

Hope this helps.

Note: Have not tested this with third party libraries, but it is working fine for my code. Tested this on Eclipse Java EE IDE for Web Developers. Version: Juno Service Release 1


That's why I always stick with the following pattern for methods:

MyReturnedType foo() {
     MyReturnedType   result = null;

     // do your stuff, modify the result or not

     return result;
}

My rules:

  1. Only one return statement, only at the end of the method (finally allowed after it)
  2. Always have a local called result which holds the returned value, starting from a default.

Naturally, the most trivial getters are exempt.


This is actually a long standing bug in Eclipse, dating back from the very first days of the IDE: https://bugs.eclipse.org/bugs/show_bug.cgi?id=40912


This feature was added to Eclipse version 4.7 M2 under Eclipse bug 40912.

To use it:

  • step over the return statement (using "Step Over" or "Step Return")
  • now the first line in the variable view will show the result of the return statement, as "[statement xxx] returned: "

See Eclipse Project Oxygen (4.7) M2 - New and Noteworthy for details.