我们从java官方教程中可以看到一个简单的Echo案例:
public class Echo {
public static void main (String[] args) {
for (String s: args) {
System.out.println(s);
}
}
}
编译运行后,Echo:
java Echo "call me echo"
那么如何从Jshell内运行呢?
jshell> public class Echo {
...> public static void main (String[] args) {
...> for (String s: args) {
...> System.out.println(s);
...> }
...> }
...> }
| created class Echo
jshell> java Echo "call me echo"
| Error:
| ';' expected
| java Echo "call me echo"
按照命令行的方式,会当场报错。
然后尝试函数调用的方式:
jshell> Echo.main("call me echo")
| Error:
| incompatible types: java.lang.String cannot be converted to java.lang.String[]
| Echo.main("call me echo")
| ^------------^
还是不行,正确的方法如下:
jshell> Echo.main(new String[] {"call", "me", "echo"});
call
me
echo
页面更新:2024-05-15
本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828
© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号