instanceof演算子の概要
1436 ワード
public class InstanofTest {
public static void main(String[] args) {
// obj Object , Object
// obj String
Object obj = "hello";
// true
System.out.println(obj instanceof Object);
// true,String Object ,obj String, true
System.out.println(obj instanceof String);
// false,Math Object , obj String
System.out.println(obj instanceof Math);
// ,obj Object, Math
// ClassCastException , obj String, Math
Math m = (Math)obj;
String str = "hello";
// , Eclipse ,str Math , Math
System.out.println(str instanceof Math);
}
}