Force Return

Select the Force Return command to return from the current method with the specified value.

You can force an early return from a method (only available when debugging on a Java SE 6 virtual machine). This returns a value from the current stack frame without executing any more instructions in the method and releases any locks obtained by synchronized blocks. A return value is created by selecting an expression and Force Return (Alt+Shift+F). This action is available from the Java editor's context menu, top level Run menu, in the Display View, and in the detail pane of the Variables View.

Forcing an early return from a non-void method requires an expression to be evaluated. For example, if a method was going to return false you could return a value of true by selecting an expression in the Display View and invoking Force Return. In the following example, elementCount is not equal to zero, and would return false (see debug hover showing the value of elementCount).

Force Return Example

From the Display View, we could enter the value we want returned, select it and use the Force Return command to force the method isEmpty() to return with that value (in the following example we will force isEmpty() to return with the value true).

Force Return Action in the Display View

This command applies to:

Related Tasks

Evaluating Expressions