Why does String.valueOf(null) throw a NullPointerException?

来源:互联网 发布:网络电影 山村姑娘 编辑:程序博客网 时间:2024/04/29 20:10

http://stackoverflow.com/questions/3131865/why-does-string-valueofnull-throw-a-nullpointerexception

 

 

Object o1=new char[3];//ok
char []c2=new Object();//编译错误

 

 

   public static String valueOf(Object obj) {
    return (obj == null) ? "null" : obj.toString();
    }

 

 

 

    public static String valueOf(char data[]) {
    return new String(data);
    }