• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java 8 in Action: Debugging Java 8 code

 
Ralf Pantförder
Greenhorn
Posts: 8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ralf
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Author
Greenhorn
Posts: 20
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

stream.filter().map().reduce()

You should write:

stream.filter()
.map()
.reduce()

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().

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic