如果用Java的伪代码来表现Java语言规范所描述的运行时语义,会是这样:// obj instanceof T
boolean result;
if (obj == null) {
result = false;
} else {
try {
T temp = (T) obj; // checkcast
result = true;
} catch (ClassCastException e) {
result = false;
}
}
用中文说就是:如果有表达式 obj instanceof T ,那么如果 obj 不为 null 并且 (T) obj 不抛 ClassCastException 异常则该表达式值为 true ,否则值为 false 。