class 的名称是表达式吗?
Is name of a class an expression?
出于好奇,class 的名称是否被视为表达式?
假设我有类似的东西
public class Hello{}
我知道 Hello.class
将 return 类型为 Class
的对象。所以这是一个表达。 但是,我们能说Hello
本身就是一个表达式吗?它是否被视为单个值?
java language specification 表示表达式的结果:
When an expression in a program is evaluated (executed), the result denotes one of three things:
A variable (§4.12) (in C, this would be called an lvalue)
A value (§4.2, §4.3)
Nothing (the expression is said to be void)
None 以上匹配项。此外,如果您阅读 section 15 of the language specification and section 6.5.6, none of the expression types matches. All expression types are described there (see jls-15.2 Forms of expressions).
的第 8 至 28 小节
结论: Class名称不是表达式,但可以是表达式的一部分。
出于好奇,class 的名称是否被视为表达式?
假设我有类似的东西
public class Hello{}
我知道 Hello.class
将 return 类型为 Class
的对象。所以这是一个表达。 但是,我们能说Hello
本身就是一个表达式吗?它是否被视为单个值?
java language specification 表示表达式的结果:
When an expression in a program is evaluated (executed), the result denotes one of three things:
A variable (§4.12) (in C, this would be called an lvalue)
A value (§4.2, §4.3)
Nothing (the expression is said to be void)
None 以上匹配项。此外,如果您阅读 section 15 of the language specification and section 6.5.6, none of the expression types matches. All expression types are described there (see jls-15.2 Forms of expressions).
的第 8 至 28 小节结论: Class名称不是表达式,但可以是表达式的一部分。