If I try to use instanceof operator with wrong class I'm getting a compile error (" Animal can not be converted to String") but with an interface I'm not getting compile time error.
For eg: In line 10 I'm getting a compile error because Animal is not a subclass of String. But in line 14 I'm not getting a compile error even though Animal does not implement List interface.
class Animal {
}
public class InstanceOf {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Animal a = new Animal();
if (a instanceof String ){ //line 10
System.out.println("True");
}
if (a instanceof List ){ //line 14
System.out.println("True");
}
}
}