Topic: 请问array类 |
Print this page |
1.请问array类 | Copy to clipboard |
Posted by: huangxd Posted on: 2006-01-25 12:27 咱们使用的数组的所有方法都是array类给提供的,对吗? 但是为什么我们定义数组的时候,不用 array 数组名 而直接用 int[] 数组名 这样定义也能使用到array类里面的方法,这是什么道理啊? |
2.Re:请问array类 [Re: huangxd] | Copy to clipboard |
Posted by: why Posted on: 2006-01-25 12:52 不是array类给提供的,因為沒有這個类. (java.util.Arrays 是不同的東西) check Chapter 10 of Java Language Specification 10.1 Array Types An array type is written as the name of an element type followed by some number of empty pairs of square brackets []. The number of bracket pairs indicates the depth of array nesting. An array's length is not part of its type. 10.8 Class Objects for Arrays Every array has an associated Class object, shared with all other arrays with the same component type. The direct superclass of an array type is Object. Every array type implements the interfaces Cloneable and java.io.Serializable. |
3.Re:请问array类 [Re: huangxd] | Copy to clipboard |
Posted by: huangxd Posted on: 2006-01-25 17:18 还是不明白,英语不好, 10.8 Class Objects for Arrays Every array has an associated Class object, shared with all other arrays with the same component type. The direct superclass of an array type is Object. Every array type implements the interfaces Cloneable and java.io.Serializable. 什么意思? 翻中国书发现以下一段话, 那数组是一种数据类型,而且是重种引用类型,数组的直接超类是object类,每个数组类型都已经实现了java.io.serializable和java.lang.cloneable接口,也就是可以对数组对象直接进行串行化处理和对象复制。数组中的元素可以通过数组属性 length进行访问。 问题是,所有的基本的数组类型都有封装类,有直接支撑给数组的类吗? 在JDK的帮助文档里面发现了一下的一些方法 java.nio.ByteBuffer.array() java.nio.CharBuffer.array() java.nio.DoubleBuffer.array() java.nio.FloatBuffer.array() java.nio.IntBuffer.array() java.nio.LongBuffer.array() java.nio.ShortBuffer.array() javax.swing.text.array 不知道有什么用? |
4.Re:请问array类 [Re: huangxd] | Copy to clipboard |
Posted by: why Posted on: 2006-01-25 20:25 >那数组是一种数据类型,而且是重种引用类型 "重种引用"又是甚麼? 类型應是type,不是class >问题是,所有的基本的数组类型都有封装类,有直接支撑给数组的类吗? 對不起,少看有關的中文書籍,不清楚"基本的数组类型"和"封装类"是甚麼,也不明白"直接支撑"的意思. 可以猜,但不想費神,猜錯更不好. API doc 裡不是寫得清楚嗎? http://java.sun.com/j2se/1.4.2/docs/api/java/nio/ByteBuffer.html#array() array |
5.Re:请问array类 [Re: huangxd] | Copy to clipboard |
Posted by: huangxd Posted on: 2006-01-25 21:11 那个地方写错了,“数组是种引用数据类型”。 以上我的意思表达的不对,总之我的意思就是说是否有种类是跟数组有关的,我不知道怎么表达这种关系,数组有length属性,那还有什么别的属性吗 ,假如有个类就是说明数组的,我们一查这个类,就知道数组还有什么方法,什么属性了。不知道元老明白我这菜鸟的困惑吗? |
6.Re:请问array类 [Re: huangxd] | Copy to clipboard |
Posted by: why Posted on: 2006-01-25 21:53 huangxd wrote: 10.1 Array Types An array type is written as the name of an element type followed by some number of empty pairs of square brackets []. The number of bracket pairs indicates the depth of array nesting. An array's length is not part of its type. 沒有array這種類(class),它在JVM是一種獨特的構造 The direct superclass of an array type is Object. Every array type implements the interfaces Cloneable and java.io.Serializable. 有Object,Cloneable和Serializable的属性--當然,Cloneable和Serializable這兩個interfaces都沒有属性,而clone() is overridden(覆蓋?). also check section 2.15 of The JavaTM Virtual Machine Specification: http://java.sun.com/docs/books/vmspec/2nd-edition/html/Concepts.doc.html#16446 |
7.Re:请问array类 [Re: huangxd] | Copy to clipboard |
Posted by: huangxd Posted on: 2006-01-26 10:05 就认为虚拟机的特异功能,看来是比较深入的知识,要努力学习英语了,争取早一天把这些纷繁复杂的知识整理清晰,让自己问心无愧,心服口服. 不知道元老是否认为我这个问题在菜鸟里面有点普遍性啊? |
8.Re:请问array类 [Re: huangxd] | Copy to clipboard |
Posted by: why Posted on: 2006-01-26 10:22 敝人以為這個不值得深究--雖然研究VM是頗有趣,但除非工作或學業所需,否則有點鑽牛角尖--閒時看看specifications已經足夠,有時間鑽研OO和software engineering等,似乎比較划算 "要知数组还有什么方法,什么属性",用一個有code complete/code assist的IDE就行了,例如在eclipse |
9.Re:请问array类 [Re: huangxd] | Copy to clipboard |
Posted by: huangxd Posted on: 2006-01-26 11:09 看来这个问题还真是个问题,数组有那么多属性但是到底是怎么来的,这个来龙去脉(有个跟数组有“特殊关系” 的类在起什么作用?)的问题还颇有深意。看来只能张一只眼闭一只眼了, |
10.Re:请问array类 [Re: huangxd] | Copy to clipboard |
Posted by: why Posted on: 2006-01-26 16:22 huangxd wrote: "The direct superclass of an array type is Object. Every array type implements the interfaces Cloneable and java.io.Serializable." Those methods listed in the Code Assist prompt are all from the Object class, except length (which is not shown in the above image)... clone() as well since it is actually overridden. |
11.Re:请问array类 [Re: huangxd] | Copy to clipboard |
Posted by: huangxd Posted on: 2006-02-01 18:20 突然想起一件事情,在eclipse里面不是可以看到原代码吗?在src.jar里面,是否可以看到array 是在什么地方继承Object,实现Cloneable 接口的? |
12.Re:请问array类 [Re: huangxd] | Copy to clipboard |
Posted by: why Posted on: 2006-02-01 18:40 huangxd wrote: 既然沒有array這個類,那麼src.jar應該不會有這些 所謂的继承Object,應該是概念上的继承,在JVM上特別處理或是compiled bytecode linked to JVM |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |