instanceof VS isAssignableFrom


public static void main(String[] argu) {
		String str = "";
		Object obj = new Object();
		String string = new String();
		System.out.println(str instanceof String);
		System.out.println(string instanceof Object);
		System.out.println(Object.class.isAssignableFrom(str.getClass()));
		System.out.println(Object.class.isAssignableFrom(obj.getClass()));
		System.out.println(Object.class.isAssignableFrom((String.class)));
		System.out.println(String.class.isAssignableFrom(Object.class));
	}


result:

true
true
true
true
true
false

你可能感兴趣的:(java)