首页 > 技术文章 > instanceof的用法①

zzzzw 2015-11-07 18:42 原文

 1 public class typeof1{
 2     private String a="zzw";
 3     public void instance(){
 4         if(a instanceof String) //判断是不是String类型的
 5         {
 6             System.out.println("hello world!");
 7         }
 8     }
 9     public static void main(String args[]){
10         new typeof1().instance();
11     }
12 }

运行结果:

hello world!

推荐阅读