Java 9中的JShell中的前向参考是什么?
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(),则它会显示“variableisdefined ”。
jshell> String notYetDeclared = "variable is declared" notYetDeclared ==> "variable is declared" jshell> forwardReference()variable is declared
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短