有人知道一个字符串
www+=空值的null后 为什么就表成wwwnull了
String s="www";s+=null;S最后的值是wwwnull

解决方案 »

  1.   

    因为这里把null当成字符串编译了吧
      

  2.   

    null是所有类的未实例化的一个对象,所以他可以转型成由低向上的转型。如果转型的几个类是有上而下继承下来,null转成最低层的那个类。
      

  3.   

    所以当NULL和字符串一起匹配的时候,变成了"NULL"向上转形了,,,所以就变成"NULL"
      

  4.   

    String Initializes    public String() {
    this.offset = 0;
    this.count = 0;
    this.value = new char[0];
        }
        public String(String original) {
    int size = original.count;
    char[] originalValue = original.value;
    char[] v;
       if (originalValue.length > size) {
          // The array representing the String is bigger than the new
          // String itself.  Perhaps this constructor is being called
          // in order to trim the baggage, so make a copy of the array.
                int off = original.offset;
                v = Arrays.copyOfRange(originalValue, off, off+size);
      } else {
          // The array representing the String is the same
          // size as the String, so no point in making a copy.
        v = originalValue;
      }
    this.offset = 0;
    this.count = size;
    this.value = v;
        }
    String类的ValueOf方法,重点再这里    public static String valueOf(Object obj) {
    return (obj == null) ? "null" : obj.toString();
        }