任何人可以解释为什么下面的if语句评估为false?
@H_403_2@public void addShapeToWhiteboard(PolyLine shape)
{
Window.alert("2");
if(shape instanceof PolyLine)
{
Window.alert("3");
this.whiteboard.add((PolyLine)shape);
Window.alert("3.5");
}
this.whiteboard.draw();
Window.alert("4");
}
它需要一个“PolyLine”对象,但是instanceof返回false,因为我收到一个“2”的警报,然后是一个警报“4”,并且没有线索,甚至是可能的.
解决方法
也许形状为空?在这种情况下,instanceof返回false.