android_String对象





  String对象:
  mView.toString()方法中,调用System.identityHashCode(this), Returns an integer hash code for the parameter. The hash code returned is the same one that would be returned by the method {@code java.lang.Object.hashCode()}, whether or not the object's class has overridden hashCode().
  System.identityHashCode(this);//取的对象id值;  调用的是根类Object的hashCode(),非子类的hashCode方法;
  new创建的字符串对象不进入字符串池;String s="abc",对于字面量定义的s都会自动调用intern,等价于String s="abc".intern();intern是native的方法,JVM维护了一个当前进程曾经出现过的字符串hash表;
  eg:String str1="a"+"b";String str2=new String("ab");  问,(str2.equals(str1));//true; (str2==str1)//false; System.identityHashCode(str1);//两个不一样;
  str1.hashCode();//两个一样;//String.java重写了hashCode的方法;//hashCode的值是根据字符串的内容来算出来的;
  String对象的内容是不可以变的;可以字符串共享,节省字符数组内存分配/拷贝;长字符串的substring尽量使用new String(longString.subString(...));
  System.arraycopy(*);//内存拷贝;速度非常快;  System.getProperty("java.vm.name");//根据名字获取对应系统属性;
  Properties p = new Properties();//public class Properties extends Hashtable<Object, Object>{ *** }
  eg:Father f1 =new Son(); 问,f1.getName();//son; f1.name;//father; //多态,执行方法是子类的,对象属性是自己的.
  方法中参数传入String与传入Integer/int一样,传递的是值,不是对象;即在public void changeString(String name){name="changeString";}//不起任何作用;
  JDK5.0之后自动装箱/拆箱功能,即int自动转化为Integer类型;    运算符重载不能用于Java.


发布了8 篇原创文章 · 获赞 7 · 访问量 12万+

猜你喜欢

转载自blog.csdn.net/liu31187/article/details/22870803