[英]JShell How to find the type of Variable or Result
如何在 JShell 中查找变量或表达式结果的类型。
在 Java 中试验按位运算符
jshell> byte b=5<<-1;
| Error:
| incompatible types: possible lossy conversion from int to byte
| byte b=5<<-1;
| ^---^
jshell> 5<<-1
$2 ==> -2147483648
jshell>
有没有像 Python type(5<<-1) 这样的替代方法来在 Jshell 中查找表达式或变量的结果类型。
刚刚发现可以通过设置反馈模式来解决。
/set feedback verbose
参考https://docs.oracle.com/javase/9/jshell/feedback-modes.htm
现在可以在响应中轻松找到表达式或变量的类型。
jshell> 5<<-1
$15 ==> -2147483648
| created scratch variable $15 : int
可以使用命令重置模式
/set feedback normal
并且可以通过简单地调用来查询当前模式
/set feedback
我找到了一种使用 /vars 命令的显式方法(我使用 JDK11 运行)
| Welcome to JShell -- Version 11
| For an introduction type: /help intro
jshell> 5<<-1
$1 ==> -2147483648
jshell> /vars
| int $1 = -2147483648
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.