1 public void method(){ 2 int a=2; 3 int b=2; 4 a=3 5 }
执行第2行:在栈创建a的引用,然后查找栈中是否存在2的地址,没有开辟一个存储2的地址
执行第3行:在栈创建a的引用,然后查找栈中是否存在2的地址,有,直接把地址赋予b
1 public boolean equals(object anobject) { 2 if (this == anobject) { 3 return true; 4 } 5 if (anobject instanceof string) { 6 string anotherstring = (string)anobject; 7 int n = value.length; 8 if (n == anotherstring.value.length) { 9 char v1[] = value; 10 char v2[] = anotherstring.value; 11 int i = 0; 12 while (n-- != 0) { 13 if (v1[i] != v2[i]) 14 return false; 15 i++; 16 } 17 return true; 18 } 19 } 20 return false; 21 }
先对内存地址比较,不相等,再对string对象中的value进行比价
string s1=“asd”; string s2=“asd”; system.out.printl(s1==s2); //输出true string s1 = new string(“asd”); string s2=“asd” system.out.printl(s1==s2); //输出false
如对本文有疑问, 点击进行留言回复!!
[杭电多校2020]第一场 1004 Distinct Sub-palindromes
Swift -- 将本地生成的UIImage进行持久化保存(存到文件中fileManager.createFile)
网友评论