Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
189 views
in Technique[技术] by (71.8m points)

java - Can I find out the return value before returning while debugging in Intellij?

With:

Object method(){
    ...
    return /* some complex expression */
}

Is there a way I can see what value will be returned while debugging? Like somehow set a breakpoint that would be hit right after the return, but before execution goes to the calling code? I'd like to be able to know what the return value is and also be able to see what values of all of the local variables are.

The way I do it now is by making a temporary variable: Object ret = /* something complex */; return ret;. But thats a hassle and also adds an extra unnecessary line of code.

Note: This is the same question as Can I find out the return value before returning while debugging in Visual Studio, but for intellij.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

On IntelliJ IDEA 2016.3: it's hidden inside the cog button of the debug panel. Ensure Show Method Return Values is checked.

IntelliJ IDEA 2016.3 "Show Method Return Values"

Use the debugger to break somewhere inside the function whose return value you'd like to see.

step into function

Step out of the function (or step over until you escape):

step out

Observe that the return value appears in your variables:

observe the return value


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...