Examples of abnormal behavior in Java

Can anyone explain why the following if statement evaluates to false?

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");
}

It needs a "polyline" object, but instanceof returns false because I receive an alarm of "2", then an alarm of "4", and there is no clue, or even possible

Solution

Maybe the shape is empty? In this case, instanceof returns false

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>