public class Test {
Object类的方法:
public int hashCode():返回该对象的哈希码值。
public final Class getClass():返回此 Object 的运行时类
public String getName():以 String 的形式返回此 Class 对象所表示的实体
public String toString():返回该对象的字符串表示。
public static String toHexString(int i):Integer类下的一个静态方法:把一个整数转成一个十六进制表示的字符串
public boolean equals(Object obj):指示其他某个对象是否与此对象,比较的是地址值,开发中我们写的类都会重写toString方法 ,比较内容
protected void finalize():用于垃圾回收对象
protected Object clone():克隆对象,对应的类要实现Cloneable接口,存储空间与原先对象堆的空间位置不同,可以通过哈希码比较
package cn;
public class Test {
/**
Object类的方法:
public int hashCode():返回该对象的哈希码值。
public final Class getClass():返回此 Object 的运行时类
public String getName():以 String 的形式返回此 Class 对象所表示的实体
public String toString():返回该对象的字符串表示。
public static String toHexString(int i):Integer类下的一个静态方法:把一个整数转成一个十六进制表示的字符串
public boolean equals(Object obj):指示其他某个对象是否与此对象,比较的是地址值,开发中我们写的类都会重写toString方法 ,比较内容
protected void finalize():用于垃圾回收对象
protected Object clone():克隆对象,对应的类要实现Cloneable接口,存储空间与原先对象堆的空间位置不同,可以通过哈希码比较
*/
public static void main(String[] args) throws CloneNotSupportedException {
Student s=new Student();
s.setName("s");
System.out.println("返回该对象的哈希码值。");
System.out.println(s.hashCode());
System.out.println("返回此 Object 的运行时类");
System.out.println(s.getClass());
System.out.println("以 String 的形式返回此 Class 对象所表示的实体");
System.out.println(s.getClass().getName());
System.out.println("返回该对象的字符串表示");
System.out.println(s.toString());
System.out.println("把一个整数转成一个十六进制表示的字符串");
System.out.println(Integer.toHexString(100));
System.out.println("比较");
System.out.println("s".equals(s.getName()));
System.out.println("克隆对象");
System.out.println(s.clone().hashCode()+"==="+s.hashCode());
}
}
输出:
返回该对象的哈希码值。
1360372376
返回此 Object 的运行时类
class cn.Student
以 String 的形式返回此 Class 对象所表示的实体
cn.Student
返回该对象的字符串表示
cn.Student@5115a298
把一个整数转成一个十六进制表示的字符串
64
比较
true
克隆对象
1667617470===1360372376
student类
package cn;
public class Student implements Cloneable{
private String name;
private int age;
public Student() {
super();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
}