java笔记--day11--类object之hashCode() and getClass()
2016-09-17 20:04
561 查看
1 Object类的概述
类 Object 是类层次结构的根类。每个类都使用 Object 作为超类。所有对象(包括数组)都实现这个类的方法。
Class Object is the root of the class hierarchy. Every class has Object as a superclass. All objects, including arrays, implement the methods of this class.
2 成员方法
public int hashCode()
public final Class getClass()
public String toString()
public boolean equals(Object obj)
protected void finalize()
protected Object clone()
本小节讲解方法hashCode()和getClass()
3 public int hashCode()
暂时当作对象的地址
4 public final Class getClass()
可以看出,返回此 Object 的运行时类。
这里的Class是一个类,该类中有一个public string getName()方法
该类以 String 的形式返回此 Class 对象所表示的实体(类、接口、数组类、基本类型或 void)名称。
5 代码实现:
类 Object 是类层次结构的根类。每个类都使用 Object 作为超类。所有对象(包括数组)都实现这个类的方法。
Class Object is the root of the class hierarchy. Every class has Object as a superclass. All objects, including arrays, implement the methods of this class.
2 成员方法
public int hashCode()
public final Class getClass()
public String toString()
public boolean equals(Object obj)
protected void finalize()
protected Object clone()
本小节讲解方法hashCode()和getClass()
3 public int hashCode()
暂时当作对象的地址
4 public final Class getClass()
可以看出,返回此 Object 的运行时类。
这里的Class是一个类,该类中有一个public string getName()方法
该类以 String 的形式返回此 Class 对象所表示的实体(类、接口、数组类、基本类型或 void)名称。
5 代码实现:
public class StudentDemo { public static void main(String[] args) { Student s1 = new Student(); System.out.println(s1.hashCode());// 57410271 Student s2 = new Student(); System.out.println(s2.hashCode());// 674267194 Student s3 = s1; System.out.println(s3.hashCode());// 57410271 Student s = new Student(); System.out.println(s.getClass());// class xsh_itcast_02.Student System.out.println(s.getClass().getName());// xsh_itcast_02.Student } }
相关文章推荐
- 多个Java object 概念简单解释
- Objective-C Runtime Programming Guide 中文翻译
- Objective-C runtime源码学习之IMP寻址(不包括消息转发部分)
- Python 里的 super() 函数和 object.__new__ ()、.__del__() 方法
- 初探Object
- object detection(物体检测)系列论文梳理
- Object有哪些公用方法?
- 论文阅读:You Only Look Once: Unified, Real-Time Object Detection
- Python下Pip安装包下的AttributeError: 'Requirement' object has no attribute 'project_name'
- 基于Ajax的数据验证——(1)CallBackObject.js
- JsonDataObjects git 下载网址
- 运行scrapy爬虫出现错误:exceptions.ImportError: libmysqlclient.so.18: cannot open shared object file
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’
- 深入理解JavaScript系列(12):变量对象(Variable Object)
- iOS开发libWeChatSDK.a(WXApiObject.o)' does not contain bitcode.
- Scala for the Impatients---(6)Objects
- vuln - SugarCRM 6.5.23 - REST PHP Object Injection Exploit
- ObjectAnimator基本使用
- Cannot assign value of type 'AnyObject' to type 'HereIsTheTypeName?'
- Object类