instanceof keyword usage

		//instanceof keyword is used to determine whether the object pointed to by a reference type variable is an instance of a class (or interface, abstract class, parent class)
		
		if(new Date() instanceof Date) {
			System.out.println("yes1");
		}
		
		if(new Date() instanceof Comparable) {
			System.out.println("yes2");
		}
		
		if(new SimpleDateFormat() instanceof DateFormat) {
			System.out.println("yes3");
		}
		String [] arr = {"34","23","12"};
		if(arr instanceof String []) {
			System.out.println("yes4");
		}
//result
yes1
yes2
yes3
yes4

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326848751&siteId=291194637