星空网 > 软件开发 > Java

[javaSE] 面向对象(Object类toString)

每一个对象,都有一个在内存中的地址哈希值,这个哈希值是十六进制的

 

调用Object对象的hashCode()方法,返回这个对象的哈希值

调用Integer.toHexString()方法,转换十六进制

调用Object对象的toString()方法,得到:类名@哈希值

通常我们会复写toString()方法,因为默认的没有太大意义

 

实现原理是类的反射

当我们创建一个对象,会在硬盘上生成xxx.class的文件,jdk定义了Class类来描述这些class文件

调用Object对象的getClass()方法,得到Class对象

调用Class对象的getName()方法,得到类的名称

public class ObjectDemo {  /**   * @param args   */  public static void main(String[] args) {    ObjectDemo od=new ObjectDemo();    System.out.println(od.toString());//输出 ObjectDemo@26f04d94    System.out.println(Integer.toHexString(od.hashCode()));//输出 26f04d94        //反射    Class c=od.getClass();    System.out.println(c.getName()+"@"+Integer.toHexString(od.hashCode()));  }}

[javaSE] 面向对象(Object类toString)

 




原标题:[javaSE] 面向对象(Object类toString)

关键词:JAVA

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

海运 非洲:https://www.goluckyvip.com/tag/97394.html
非洲海运港口:https://www.goluckyvip.com/tag/97395.html
国际海运阿联酋:https://www.goluckyvip.com/tag/97396.html
海运 越南:https://www.goluckyvip.com/tag/97397.html
中国阿联酋海运:https://www.goluckyvip.com/tag/97398.html
伊朗海运港口:https://www.goluckyvip.com/tag/97399.html
云南抚仙湖旅游攻略更佳行程安排,景点攻略大全:https://www.vstour.cn/a/408242.html
珠海附近过年旅游景点 珠海附近过年旅游景点免费:https://www.vstour.cn/a/408243.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流