getClass 和instanceof使用场景

判断一个类的引用类型

getClass()==x.class;

 

判断一个类是否是一个类或者该类子类的实例(常用)

instanceof

public void fun1()
	{
		Object o=new String();
		System.out.println(o.getClass()==String.class);
		System.out.println(o instanceof String);
	}

  

posted on 2017-08-04 10:49  lkjhgfdsa123  阅读(341)  评论(0编辑  收藏  举报