Object type converts to an Integer

Object also has its own type, if Object types of data directly into strong Integer type conversion will appear abnormal

        Object o = new Object();
        Integer i = (Integer) o;    //java.lang.ClassCastException: java.lang.Object cannot be cast to java.lang.Integer

Object type is converted to an Integer type Object first two methods :( by toString () or String.valueOf () to a String, and then by calling the method Integer String class type conversion tool type Integer, you should try abnormal type conversion)

  1. Integer.parseInt(obj.toString());        
  2. Integer.parseInte(String.valueof(obj));

Guess you like

Origin www.cnblogs.com/vegetableDD/p/11646037.html