O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

For a deeper understanding of the concepts here, let's modify Clazz03:

public class Clazz03 {  public void method(String action){    if(action != null){      System.out.println(action);      return;    }    System.out.println("Print the stack trace:");    Thread.currentThread().dumpStack();  }}

The result will be the following:

Alternatively, we can get a similar output by using Throwable instead of Thread:

new Throwable().printStackTrace();

It does look very familiar:

A similar result will produce each of the following two lines:

Arrays.stream(Thread. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required