If the type of the left operand is an interface I, the type of the right operand must be a subinterface of I, or a class that implements I, or the null value. : Reference Type Casting « Type Casting « SCJP
publicclass MainClass{
publicstaticvoid main(String[] argv){
MyInterface myClass = new MyClass();
}
}
class MyClass{
}
interface MyInterface{
}
class MySubclass extends MyClass implements MyInterface{
}
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Type mismatch: cannot convert from MyClass to MyInterface
at MainClass.main(MainClass.java:3)
If the type of the left operand is an interface I, the type of the right operand must be a subinterface of I, or a class that implements I, or the null value.