Có vẻ như, đối tượng JShell
được tạo bên trong một số JShell
khác không có quyền truy cập vào phạm vi JShell
của cha mẹ. Ví dụ:Truy cập vào "phạm vi gốc" trong JShell
jshell> int x = 1;
x ==> 1
jshell> x
x ==> 1
jshell> jdk.jshell.JShell js = jdk.jshell.JShell.create();
js ==> [email protected]
jshell> js.eval("x");
$4 ==> [SnippetEvent(snippet=Snippet:ErroneousKey#1-x,previousStatus=NONEXISTENT,status=REJECTED,isSignatureChange=false,causeSnippetnull)]
jshell> js.eval("int x = 2;");
$5 ==> [SnippetEvent(snippet=Snippet:VariableKey(x)#2-int x = 2;,previousStatus=NONEXISTENT,status=VALID,isSignatureChange=true,causeSnippetnullvalue=2)]
jshell> js.eval("x");
$6 ==> [SnippetEvent(snippet=Snippet:ExpressionKey(x)#3-x,previousStatus=NONEXISTENT,status=VALID,isSignatureChange=true,causeSnippetnullvalue=2)]
Bằng cách nào đó, có thể hiển thị phạm vi cha mẹ cho con không?
Bạn có nghĩa là bằng cách nào đó để truy cập giá trị của 'x' từ' JShell' instance 'js' trong mẫu của bạn? – nullpointer
@nullpointer chính xác – Andremoniy