点的长度在Java中 - 找到它的定义 [英] dot length in java - finding its definition
问题描述
在哪个班是在Java中(例如,用于数组长度)定义的长度
字段?
我将能够看到它定义说,在对象
类?
编辑:?为什么这个领域如此设计(与安全或内存使用效率相关的任何东西)
EDIT : Why was this field so designed(any thing related with security or memory efficiency)?
推荐答案
数组类型在Java特别。这是 JLS 10.7的数组成员
Array types are special in Java. This is an excerpt from JLS 10.7 Array Members
数组类型的成员都是如下:
The members of an array type are all of the following:
- 的
公众最终
字段长度
,其中包含数组的组件数量(长度可正可零)。 - 的
公共
方法克隆
,这将覆盖同名类中的方法对象
并没有抛出检查异常。数组类型的克隆方法的返回类型T []
是T []
。 - 所有成员继承自Object类;未继承的对象的唯一方法是它的
克隆
方法。
- The
public final
fieldlength
, which contains the number of components of the array (length may be positive or zero). - The
public
methodclone
, which overrides the method of the same name in classObject
and throws no checked exceptions. The return type of the clone method of an array typeT[]
isT[]
. - All the members inherited from class Object; the only method of Object that is not inherited is its
clone
method.
尽管这样,还是有老站着的错误,当你使用的阵列反思:既不长度
也不克隆
可以通过反射找到(错误#5047859 ,的bug# 4987375 )。
Despite this, there are still old-standing bugs when you're using reflection on arrays: neither length
nor clone
could be found through reflection (bug# 5047859, bug# 4987375).
成员都不是继承从任何超类中的传统方式;所有数组类型从对象
直接延伸。这种特殊待遇可能是为什么在第一个地方存在这些缺陷。
Neither member is inherited in the traditional way from any superclass; all array types extends from Object
directly. This "special treatment" is likely why these bugs exist in the first place.
这是否意味着永远一眼就能看到被定义的长度是可变的?
"does this mean that never will one be able to see the length variable being defined?"
有没有实际的源$ C $ C数组类型。同样,这些类型是特别;在JVM刚刚翻出这些类型的出是必需的,他们只要一顶帽子。你不会看到为数组类型的.java
源文件 INT []。类
(即所有类型 INT
阵列)。
There is no actual source code for array types. Again, these types are special; the JVM just pulls out these types out of a hat whenever they're required. You will not see a .java
source file for the array type int[].class
(i.e. the type of all int
array).
所以,不,你将不能够的见的的长度
的字段的定义。
So, no, you will not be able to see the length
field defined.
有关进一步的阅读,这里有关于Java反射的一些信息:
For further reading, here are some information on Java Reflection:
- The Java Tutorials: Reflection API
- Advanced Language Topic technical article: Using Java Reflection
这篇关于点的长度在Java中 - 找到它的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!