Java中任何对象的编译时间和运行时类型有什么区别?我正在阅读有效Java书籍,Joshua Bloch多次提及项目26中编译时间类型和数组实例的运行时类型,主要是为了描述抑制强制转换警告有时是安全的.
// Appropriate suppression of unchecked warning
public E pop() {
if (size == 0)
throw new EmptyStackException();
// push requires elements to be of type E, so cast is correct
@SuppressWarnings("unchecked") E result = (E) elements[--size];
elements[size] = null; // Eliminate obsolete reference
return result;
}
Run Code Online (Sandbox Code Playgroud)
在这里,作者正在讨论这些不同类型types的数组上下文.但通过这个问题,我想了解compile time typesvs run time types对于任何类型的对象的区别.