JShell是一个命令行工具,它使我们可以输入Java语句(简单语句,复合语句,甚至完整的方法和类),对其进行评估并打印结果。
前向引用是指引用我们在JShell中键入的任何代码中都不存在的方法,变量或类的命令。在JShell中按顺序输入和评估代码后,这些前向引用已暂时无法解析。JShell支持向前引用方法机构,返回类型,参数类型,变量的类型,以及内一类。
在下面的代码片段中,在Jshell中创建了一个方法forwardReference()。在声明变量之前,无法调用此方法。如果我们试图尝试调用此方法,它将引发警告消息:“试图forwardReference()
调用在声明了变量notYetDeclared之前无法调用的方法”
C:\Users\User>jshell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell> void forwardReference() { ...> System.out.println(notYetDeclared); ...> } | created method forwardReference(), however, it cannot be invoked until variable notYetDeclared is declared jshell> forwardReference()| attempted to call method forwardReference() which cannot be invoked until variable notYetDeclared is declared
在下面的代码片段中,我们声明了返回字符串的“notYetDeclared ”变量。最后,如果我们在JShell中调用forwardReference(),则它会显示“ variable is defined”。
jshell> String notYetDeclared = "variable is declared" notYetDeclared ==> "variable is declared" jshell> forwardReference()variable is declared
热门文章
- 1月4日 - 最高速度18.9M/S,2025年Nekobox每天更新免费节点订阅地址
- 动物诊疗许可证申请书范本(动物诊疗许可证申请表填写样板)
- 1月29日 - 最高速度18.9M/S,2025年Nekobox每天更新免费节点订阅地址
- 动物疫苗价格查询表最新消息图片大全(动物 疫苗)
- 2月3日 - 最高速度20.8M/S,2025年Nekobox每天更新免费节点订阅地址
- Java 9中的JShell中的前向参考是什么?
- 动物疫苗检测中心电话 动物疫苗检测中心电话号码
- 使用Nginx实现多个Tomcat负载均衡
- 1970年4月27日农历是多少(70年4月27号农历是)
- 3月15日 - 最高速度22.5M/S,2025年Nekobox每天更新免费节点订阅地址