相关疑难解决方法(0)

instanceof - 不兼容的条件操作数类型

以下编译正常:

  Object o = new Object();
  System.out.println(o instanceof Cloneable);
Run Code Online (Sandbox Code Playgroud)

但这不是:

  String s = new String();
  System.out.println(s instanceof Cloneable);
Run Code Online (Sandbox Code Playgroud)

抛出编译器错误.

问题是什么?

java instanceof cloneable

54
推荐指数
3
解决办法
4万
查看次数

什么时候应该使用instanceof,何时不使用instanceof

我已经阅读了各种文章,但我仍然不知道为什么不应该使用instanceof.kindlylet我知道你的想法.

java

14
推荐指数
3
解决办法
8446
查看次数

标签 统计

java ×2

cloneable ×1

instanceof ×1