有人可以向我解释一下编译器在第一次投射时不会抱怨,但是在第二次投射中是否会抱怨?
interface I1 { }
interface I2 { }
class C1 implements I1 { }
class C2 implements I2 { }
public class Test{
public static void main(){
C1 o1 = new C1();
C2 o2 = new C2();
Integer o3 = new Integer(4);
I2 x = (I2)o1; //compiler does not complain
I2 y = (I2)o3; //compiler complains here !!
}
}
Run Code Online (Sandbox Code Playgroud)