jshell - unable to find printf

java, java-9, jshell

Solution

An earlier version of JShell had a `printf` method pre-defined but it was removed from early access builds. You can of course define your own printf method:

jshell> void printf(String format, Object... args) { System.out.printf(format, args); }

Or you can get the printing methods that were in earlier builds back by starting JShell with:

jshell --start DEFAULT --start PRINTING

(If you use only `--start PRINTING` you won't get the default imports.)

For more information see bug JDK-8172102 in the Java bug database and changeset b2e915d476be which implemented it.

Problem

Why does my jshell instance (JDK Version 9-ea) unable to identify `printf()` statement ? Below is the error I observe, ``` jshell> printf("Print number one - %d",1) | Error: | cannot find symbol | symbol: method printf(java.lang.String,int) | printf("Print number one - %d",1) | ^----^ ``` I am able to access printf, provided I specify it in a regular way. ``` jshell> System.out.printf("Print number one - %d",1) Print number one - 1$1 ==> java.io.PrintStream@1efbd816 ``` Any pointers?

Original source