编译时
- 编译器把源代码翻译成机器能识别的代码。比如Java将代码编译成JVM识别的字节码。
运行时
编译时 & 运行时
@Test
public testThrow() {
System.out.println(1);
}
@Test
public void testThrow() {
String[] a = new String[]{"a", "b"};
System.out.println(a[10]);
}
public class CommonTest {
static final int n1 = 3;
static final int n2 = 4;
static int n3 = 5;
static int n4 = 6;
@Test
public void testCompileRun() {
int a = n1 * n2;
int b = n3 * n4;
}
}
重载、重写、泛型
- 重载在编译时执行
- 重载的方法参数列表不一样,当指定了参数列表,则方法也就指定了
- 重写在运行时执行
- 重写的方法参数列表一致,只是实现逻辑不一样,则需要在运行时才能确定是哪个方法执行
- 泛型(类型检测)在编译时执行
- 编译器会在编译时对泛型类型进行检测,并吧他重写成实际的对象类型(非泛型代码),然后被JVM执行。也称作"类型擦除"