目前使用的方法是"int".equal(o.getClass().getName())来判断的,字符串比较效率应该不高。而且运气不好要分别和int,String,float,long分别比较一次才会知道原来o的类型是boolean.

解决方案 »

  1.   

    if (o.getClass().isPrimitive()) { //判断是不是基本类型
        //
    }如果要具体到哪一种类型
    if (o.getClass() == int.class) { //float.class boolean.class so on
        //int type
    }
      

  2.   


          Object x = 0;      if(x instanceof Integer) {
             
          }
          else if(x instanceof Float) {
             
          }
          else if(x instanceof Long) {
             
          }
          else if(x instanceof String) {
             
          }
          else if(x instanceof Boolean) {
             
          }
    高效不高效就不知道了。