tommy-huang

instanceof:是java中用来判断一个对象属于哪个类型的关键字

(instanceof是instance和of两个单词组成,但of并没有大写)

eg:

public class Test{

      public static void main(String[] args){

            String abc = new String("i love you");

           if(abc instanceof String){

                System.out.println(abc+" is a String type variable.");

           }

      }

}

 

也可以看看这个例子:http://rodney.cnblogs.com/archive/2005/08/18/instanceof.html

并且其中说到,与其使用instanceof,还不如多使用面向对象的 多态(子类可以代替父类来使用)

分类:

技术点:

相关文章:

  • 2021-09-13
  • 2021-11-29
  • 2022-01-23
  • 2021-08-04
  • 2021-07-14
  • 2021-11-16
  • 2022-02-07
  • 2021-11-17
猜你喜欢
  • 2021-11-17
  • 2021-07-04
  • 2022-01-05
  • 2021-12-19
  • 2021-11-17
  • 2022-01-07
相关资源
相似解决方案