Java数组: Difference between Component and Element

标签 java arrays abstract-syntax-tree

我正在阅读 API对于 ArrayType 类,它是 ASTNode 的子类。

有一个方法 getComponentType() 和一个方法 getElementType()

对于语句:int[] list = new int[50],上述两个方法都返回类型 - int

有人知道这两种方法之间的区别吗?

最佳答案

Javadoc 有一个包含简短描述的表格,但您必须向下滚动才能阅读完整的说明。对于 getComponentType(),它表示:

Returns the component type of this array type. The component type may be another array type.

而对于getElementType(),它表示:

Returns the element type of this array type. The element type is never an array type.

This is a convenience method that descends a chain of nested array types until it reaches a non-array type.

例如,int[][] 的“组件类型”为 int[],但“元素类型”为 int.

关于Java数组: Difference between Component and Element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17033454/

相关文章:

java - 图像在垂直滚动 Pane 视口(viewport)中消失

二维数组中的php数组匹配

javascript - 从字符串元素数组创建 DOM 元素,然后将结果加入 render()

python - 以正确的顺序从数组构建 block 矩阵

java - 当测试按设置运行时,单元测试失败?

java - JSON解析问题

python - 限制 Python 的语法以安全地执行用户代码。这是一种安全的方法吗?

c - 如何在程序中自动插入 pragma

java - 将 startForeground 与 android 服务一起使用

Python DEAP 个体到 AST