B. *_*son 12 java instanceof jshell java-11
当在第33行重新声明Integer'a'时,为什么jshell将引用变量显示为Integer的实例(参考第38和39行)?重新声明后,第34行显示'a'设置为null.当'a'在第6行声明但未给出值时,或在第22行中重置为null时,'a'不被视为Integer的实例.我希望当引用变量被重新声明时,因为它的值为null,所以它不是一个类型的实例; 然而,事实并非如此.
01: java-lava:~ cafedude$ jshell
02: | Welcome to JShell -- Version 11
03: | For an introduction type: /help intro
04:
05: jshell> Integer a;
06: a ==> null
07: | created variable a : Integer
08:
09: jshell> a instanceof Integer;
10: $2 ==> false
11: | created scratch variable $2 : boolean
12:
13: jshell> a = 1;
14: a ==> 1
15: | assigned to a : Integer
16:
17: jshell> a instanceof Integer;
18: $4 ==> true
19: | created scratch variable $4 : boolean
20:
21: jshell> a = null;
22: a ==> null
23: | assigned to a : Integer
24:
25: jshell> a instanceof Integer;
26: $6 ==> false
27: | created scratch variable $6 : boolean
28:
29: jshell> a = 1;
30: a ==> 1
31: | assigned to a : Integer
32:
33: jshell> Integer a;
34: a ==> null
35: | modified variable a : Integer
36: | update overwrote variable a : Integer
37:
38: jshell> a instanceof Integer;
39: $9 ==> true
40: | created scratch variable $9 : boolean
Run Code Online (Sandbox Code Playgroud)
小智 3
问题是,虽然它说它被设置为空,但实际上并非如此。有关更多详细信息,请参阅错误中添加的注释。
我已将错误标题更改为:JShell:应重置重新声明的变量
我将尝试在 JDK 12 中修复。
第二个问题不是一个 bug,Java 不允许不为 true 的 instanceof 运算符——行为与 javac 完全匹配。
| 归档时间: |
|
| 查看次数: |
143 次 |
| 最近记录: |