Java的异常行为的例子

前端之家收集整理的这篇文章主要介绍了Java的异常行为的例子前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
任何人可以解释为什么下面的if语句评估为false?
  1. public void addShapeToWhiteboard(PolyLine shape)
  2. {
  3. Window.alert("2");
  4. if(shape instanceof PolyLine)
  5. {
  6. Window.alert("3");
  7. this.whiteboard.add((PolyLine)shape);
  8. Window.alert("3.5");
  9. }
  10. this.whiteboard.draw();
  11. Window.alert("4");
  12. }

它需要一个“PolyLine”对象,但是instanceof返回false,因为我收到一个“2”的警报,然后是一个警报“4”,并且没有线索,甚至是可能的.

解决方法

也许形状为空?在这种情况下,instanceof返回false.

猜你在找的Java相关文章