'super'、'class' 和 'this' 关键字在 java 中定义在哪里?
Where are 'super', 'class' and 'this' keywords defined in java?
昨晚让我印象深刻,这些关键字到底是在哪里定义的。例如,假设我们有
public class A {
public void doSomething() {
// Only for illustration.
A.super.hashCode();
A.class.getClass();
}
}
从用法上看,'super'、'class'、'this'这几个关键字看起来是静态的(class级)。这些不是静态的吗? '.'[点运算符] 如何知道它必须在此处表现不同而不将它们视为静态。
where exactly are these keywords defined
它们在 Java Language Specification #3.9 中定义。
From the usage, these keywords 'super', 'class', 'this' looks like static (class level).
不,他们没有。考虑 a.hashCode()
.
Are these not static and something else?
是的,是的。
How does the '.'[dot operator] know it has to behave differently here and not consider them as static.
与任何其他对象引用相同。这是一个语义分析任务。
昨晚让我印象深刻,这些关键字到底是在哪里定义的。例如,假设我们有
public class A {
public void doSomething() {
// Only for illustration.
A.super.hashCode();
A.class.getClass();
}
}
从用法上看,'super'、'class'、'this'这几个关键字看起来是静态的(class级)。这些不是静态的吗? '.'[点运算符] 如何知道它必须在此处表现不同而不将它们视为静态。
where exactly are these keywords defined
它们在 Java Language Specification #3.9 中定义。
From the usage, these keywords 'super', 'class', 'this' looks like static (class level).
不,他们没有。考虑 a.hashCode()
.
Are these not static and something else?
是的,是的。
How does the '.'[dot operator] know it has to behave differently here and not consider them as static.
与任何其他对象引用相同。这是一个语义分析任务。