Force Return
Select the Force Return command to return from the current method with the speified 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 ofelementCount
).
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 forceisEmpty()
to return with the valuetrue
).
This command applies to:
- Java Editor
- Display View
- Detail Pane (in the Expressions View and Variables View)
- Run Menu