According to k&B
Java 5 table 4-1 pg 286 if first operand is ref of Foo[] and instanceof operand is Foo Bar Face, it will return false but it is returning true. Can you explain?
interface Face{}
class Bar implements Face{}
public class Foo extends Bar{
public static void main(
String [] args){
Foo[] f = new Foo[5];
if (f instanceof Foo[]) System.out.println("true"); // Prints true
// if (f instanceof Foo) System.out.print("1 "); // it does not compile
}
}
What should I do fix the code?
Thanks