class A {}
class B extends A {}
class C extends A {}
Run Code Online (Sandbox Code Playgroud)
A x = new B();
B y = new B();
Run Code Online (Sandbox Code Playgroud)
x instanceof C
y instanceof C
Run Code Online (Sandbox Code Playgroud)
为什么工作正常y instanceof C时会出现编译错误(不兼容的类型)x instanceof C?
该线程一直在工作,直到它被中断,但它不时休眠:
public void run() {
while (!Thread.interrupted()) {
//A TASK HERE
try {
Thread.sleep((long) (500 + Math.random() * 100));
} catch (InterruptedException e) {
interrupt(); //it was interrupted while it was sleeping
}
}
}
Run Code Online (Sandbox Code Playgroud)
目的是通过中断线程来杀死线程。我可以像我一样重新中断自己还是应该stop = true在异常条款中设置一个标志?
我正在尝试在 Debian 10 buster 上启动 jshell。我从 Oracle 下载了 jdk-16_linux-x64_bin.tar.gz 并将其解压到我的主目录中的“jdk-16”中。我已经设置了 PATH 和 JAVA_HOME:
~$ export PATH=~/jdk-16/bin:$PATH
~$ export JAVA_HOME=~/jdk-16
~$ javac --version
javac 16
~$ java --version
java 16 2021-03-16
Java(TM) SE Runtime Environment (build 16+36-2231)
Java HotSpot(TM) 64-Bit Server VM (build 16+36-2231, mixed mode, sharing)
Run Code Online (Sandbox Code Playgroud)
测试“Hello world”程序在此环境下能否成功编译并运行。但是,当我尝试运行 jshell 时,出现以下错误:
~$ jshell
| Welcome to JShell -- Version 16
| For an introduction type: /help intro
Exception in thread "main" java.io.IOError: java.lang.StringIndexOutOfBoundsException: String index out of range: 5
at jdk.internal.le/jdk.internal.org.jline.utils.Curses.tputs(Curses.java:62) …Run Code Online (Sandbox Code Playgroud)