标签:
一:概念
java.long.object
Object类是所有Java类的祖先。每个类都使用 Object 作为超类。
二:方法概览
//equals方法源码
public boolean equals(Object obj){ return(this == obj); }
//String类中对equals方法的重写
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类中对hashcode()方法的重写 public int hashCode() { 2 int h = hash; //Default to 0 ### String类中的私有变量, 3 if (h == 0 && value.length > 0) { //private final char value[]; ### Sting类中保存的字符串内容的的数组 4 char val[] = value; 5 6 for (int i = 0; i < value.length; i++) { 7 h = 31 * h + val[i]; 8 } 9 hash = h; 10 } 11 return h;
12 }
//没有重写hashCode方法的类,直接返回32位对象在JVM中的地址;Long类重写了hashCode方法,返回计算出的hashCode数值 public class ComHashcode{ 2 public static void main(String[] args) throws Exception { 3 ComHashcode a = new ComHashcode(); 4 ComHashcode b = new ComHashcode(); 5 System.out.println(a.hashCode()); //870919696 6 System.out.println(b.hashCode()); //298792720 7 8 Long num1 = new Long(8); 9 Long num2 = new Long(8); 10 System.out.println(num1.hashCode()); //8 11 System.out.println(num2.hashCode()); //8 12 } 13 }
3.wait()与sleep()
标签:
原文地址:http://www.cnblogs.com/nomorelies/p/5879250.html