问题描述
这两个接口的一个用途,就是写注释处理器。
One usage of these two interface, is to write annotation processor.
作为Java初学者,我发现,是由这两个包加间接的水平: javax.lang.model.element中的
&安培; javax.lang.model.type中
来提供关于Java 接口
和java 类元code>混乱。
As a java beginner, I find the level of indirection that is added by these two packages:javax.lang.model.element
& javax.lang.model.type
to provide metadata about java interface
and java class
confusing.
.........
.........
Java的文档注释说,
java doc comments say,
TypeElement
重新presents一个类
或接口
程序元素。提供对有关类型及其成员的信息。请注意,枚举
类型是一种类和注释类型是一种接口
。
的declaredType
重新presents一个声明类型,是一个类
键入或接口
类型。这包括参数化类型,如 java.util.Set中的<弦乐方式>
以及原始类型
DeclaredType
represents a declared type, either a class
type or an interface
type. This includes parameterized types such as java.util.Set<String>
as well as raw types.
两者之间的区别:
而在 TypeElement
重新presents一个类
或接口
的元素的一个的declaredType
重新presents一个类
或接口
的键入的,后者是使用(或调用的)前的。
我如何区分行话的元素的距离的键入的?例如:如何为类
的元素的从类不同
的键入?请帮我用一个例子。
How do I differentiate the jargon element from type? For example: How is class
element different from class
type? Please help me with an example.
推荐答案
的元素的是,你用它来组成一个软件部分,即 ExecutableElement
■哪些,顾名思义,包含可执行code,它描述了一种存储 VariableElement
和 TypeElement
■哪些合计持有这些。这是Java编程语言的一个特殊属性(如面向对象的语言),有没有顶级的功能,也没有全局变量没有 TypeElement
,它们被定义的。
The elements are the parts that you use to compose a software, i.e. ExecutableElement
s which, as the name suggests, contain executable code, VariableElement
s which describe a kind of storage and TypeElement
s which hold these together. It’s a special property of the Java programming language (as an object oriented language) that there are no top-level functions nor global variables without a TypeElement
, in which they are defined.
在换句话说,如果你写一个Java程序,你将永远有含有至少一种类型声明至少有一个的.java
源文件。这 TypeElement
将有可能至少包含一个 ExecutableElement
来弥补一个有用的软件。在 TypeElement
可以包含多个 ExecutableElement
S, VariableElement
和嵌套 TypeElement
秒。这是你的程序的结构的
In other words, if you write a Java program, you will always have at least one .java
source file containing at least one type declaration. That TypeElement
will likely contain at least one ExecutableElement
to make up a useful software. The TypeElement
may contain multiple ExecutableElement
s, VariableElement
s and nested TypeElement
s. That’s the structure of your program.
A 键入的是,只要你声明成员或局部变量,你使用的东西,同时也宣告一个超类或-interface时。但是,让我们关注的变量,以更好地理解:
A type is something which you use whenever you declare a member or local variable, but also when declaring a super class or -interface. But let’s focus on variables, for a better understanding:
一个变量可以有一个原语类型,这是固有的编程语言,它也可以有一个类型,其存在是隐含的,例如当有键入 X
,你也可以使用数组类型 X []
在一个变量声明,但只在声明类型的是必须有相应的 TypeElement
,再presenting的东西,开发商写(或已生成的类型一个工具)。泛型还允许您撰写的类型,例如声明类型的变量设置 - LT ;?扩展号码&GT;
,而设置
和编号
的声明类型的已相应的程序元素...
A variable can have a primitive type, which is intrinsic to the programming language, it can also have a type whose existence is implied, e.g. when there is a type X
, you can also use the array type X[]
in a variable declaration, but only the declared type is a type which must have a corresponding TypeElement
, representing something, a developer has written (or has been generated by a tool). Generics also allow you to compose types, e.g. declare a variable of type Set<? extends Number>
whereas Set
and Number
are declared types which have corresponding program elements…
这篇关于理解“TypeElement'和'的declaredType”在Java接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!