jshell-无法找到printf [英] jshell - unable to find printf

查看:98
本文介绍了jshell-无法找到printf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我的jshell实例(JDK版本9-ea)无法识别printf()语句?以下是我观察到的错误,

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

有指针吗?

推荐答案

JShell的早期版本具有预定义的printf方法,但已从早期访问版本中删除了该方法.您当然可以定义自己的printf方法:

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); }

或者您可以通过以下方式启动JShell来获得早期构建中的打印方法:

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

jshell --start DEFAULT --start PRINTING

(如果仅使用--start PRINTING,则不会获得默认导入.)

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

有关更多信息,请参见Java错误中的错误 JDK-8172102 数据库和变更集 b2e915d476be 实现了它.

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

这篇关于jshell-无法找到printf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆