File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Features new in Java 8 and the fly likes Java 8 in Action: Debugging Java 8 code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Features new in Java 8
Bookmark "Java 8 in Action: Debugging Java 8 code" Watch "Java 8 in Action: Debugging Java 8 code" New topic

Java 8 in Action: Debugging Java 8 code

Ralf Pantförder

Joined: May 10, 2010
Posts: 8
Hi Raoul-Gabriel, Mario, and Alan,

I noticed there is a chapter in the book on "Tools, testing, debugging". I wonder whether debugging remains manageable and intuitional in such concise code employing streams, lambda expressions and the :: operator. Did you already have the chance to gain experience in debugging Java 8 code in some IDE? For instance, have you tried stepping into a lambda expression?

Thanks and regards
Mike. J. Thompson
Ranch Hand

Joined: Apr 17, 2014
Posts: 679
Interesting question. I just tried with the following code (in eclipse):

I put a breakpoint on the first line of main(...), and then stepped into debugLambda(...). I then stepped into function.apply(...), and the execution pointer jumped back to the lambda in main(...). The variables box in the debug perspective showed one local variable called 'string', that had the value "12". Looked perfectly sensible and usable to me.
Raoul Gabriel

Joined: Apr 22, 2014
Posts: 20
Hi Ralf,

we renamed the chapter "Refactoring, Testing, and Debugging". The new ToC will be updated soon and the content should be up shortly. In a nutshell, this chapter has more emphasis on refactoring: we discuss patterns to apply in your code and how typical object-oriented design patterns can be refactored using lambdas

Regarding debugging, you can set break points in a lambda expressions as you would normally do in your code. However, make sure the lambda is on multiple lines so you can set a line individually. Similarly for a stream pipeline. Instead of writing:


You should write:


So you can set break points on the individual operations.

The Debugging section specifically discusses on to examine stack traces (lambda expression makes things slightly less readable) and how to debugg/log information in a stream pipeline using the operation peek().

I agree. Here's the link:
subject: Java 8 in Action: Debugging Java 8 code
It's not a secret anymore!