Java记录 -22- Java的基类Object详解
2015-09-03 18:34
561 查看
Java的基类Object详解
Java的JDK文档要经常查阅使用,最好查看英文的文档。
Oracle官方在线 Java API Specifications
http://www.oracle.com/technetwork/java/api-141528.html
java.lang.Object 类,java.lang包在使用的时候无需显示导入,编译时由编译器自动帮助我们导入。
API(Application Programinga Interface),应用编程接口。
Object obj = new Object();
System.out.println(obj);
System.out.println(obj.toString());
上面打印的两个内容一样。当打印引用时,实际上会打印出引用所指向对象的 toString()方法的返回值,因为每个类都直接或间接的继承自Object,而Object类中定义了 toString(),因此每个类都有 toString()这个方法。
String str = "aaa";
System.out.println(str);
System.out.println(str.toString());
两个输出内容都为 aaa,按照上面的理解,Sting一定重写了Object的 toString()方法。
当打印一个引用对象时,会显示例如:java.lang.Object@c17164。为什么会打印这么一个串呢?我们通过查看Object类的toString()方法就可以知道。
6. 关于进制的表示,16进制,逢16进一,16进制的数字包括:0~9,A,B,C,D,E,F
Java的JDK文档要经常查阅使用,最好查看英文的文档。
Oracle官方在线 Java API Specifications
http://www.oracle.com/technetwork/java/api-141528.html
java.lang.Object 类,java.lang包在使用的时候无需显示导入,编译时由编译器自动帮助我们导入。
API(Application Programinga Interface),应用编程接口。
Object obj = new Object();
System.out.println(obj);
System.out.println(obj.toString());
上面打印的两个内容一样。当打印引用时,实际上会打印出引用所指向对象的 toString()方法的返回值,因为每个类都直接或间接的继承自Object,而Object类中定义了 toString(),因此每个类都有 toString()这个方法。
String str = "aaa";
System.out.println(str);
System.out.println(str.toString());
两个输出内容都为 aaa,按照上面的理解,Sting一定重写了Object的 toString()方法。
当打印一个引用对象时,会显示例如:java.lang.Object@c17164。为什么会打印这么一个串呢?我们通过查看Object类的toString()方法就可以知道。
public String toString() Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode()) Returns: a string representation of the object.java.lang.Object@c17164 类名+@+地址的十六进制表示形式
6. 关于进制的表示,16进制,逢16进一,16进制的数字包括:0~9,A,B,C,D,E,F
相关文章推荐
- objective-C编程 程序设计摘要
- Objective-C 【This is ARC】
- Objective-C 【This is ARC】
- oc学习笔记
- Java之Object.WAIT()
- Oreilly Cocoa and Objective C Up and Running
- Objective-C使用位运算设计可复选的枚举
- 【《Objective-C 高级编程》 学习笔记--GCD】
- objective-c 下面int 和 NSData数据 互相转换的方法
- Objective-C之类的声明与创建
- Objective-C类初始化:load与initialize
- Object对象详解(四)之wait与notify/notifyAll
- Object-C中的Category
- 视频播放插件 swfobject
- js报错“TypeError: 'stepUp' called on an object that does not implement interface HTMLInputElement”
- CRITICAL_OBJECT_TERMINATION (f4)
- Objective-C 学习笔记 9 多态,动态类型,动态绑定
- JSONObject介绍与操作
- 编写高质量的Objective-C代码
- objective c代码规范