interface FatherInterface{}
public class TestInstance implements FatherInterface{
static String str1;
static String str2 = new String("good");
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
TestInstance ti = new TestInstance();
if(ti instanceof FatherInterface){
System.out.println("ti true");
}
else{
System.out.println("ti false");
}
if(str1 instanceof String){
System.out.println("str1 true");
}
else{
System.out.println("str1 false");
}
if(str2 instanceof String){
System.out.println("str2 true");
}
else{
System.out.println("str2 false");
}
}
}
输出内容:
ti true
str1 false
str2 true
可见,只有赋值后才可以用instanceof来判断