gpt4 book ai didi

java - 限定名称和字段访问表达式有什么区别?

转载 作者:搜寻专家 更新时间:2023-10-31 08:03:52 25 4
gpt4 key购买 nike

来自JLS details on protected access :

Let C be the class in which a protected member is declared. Access is permitted only within the body of a subclass S of C.

In addition, if Id denotes an instance field or instance method, then:

If the access is by a qualified name Q.Id, where Q is an ExpressionName, then the access is permitted if and only if the type of the expression Q is S or a subclass of S.

If the access is by a field access expression E.Id, where E is a Primary expression, or by a method invocation expression E.Id(. . .), where E is a Primary expression, then the access is permitted if and only if the type of E is S or a subclass of S.

限定名字段访问表达式有什么区别?

最佳答案

如果表达式名称的形式为 Q.Id,则 Q 已被分类为包名称、类型名称或表达式名称。

字段访问表达式的含义使用与限定名称相同的规则来确定,但受到表达式不能表示包、类类型或接口(interface)类型这一事实的限制。

在oracle的网站上找到了上面的文字。

简单来说:

  1. 限定名称是指在声明中携带 parent 信息。例如Pack1.Pack2.Pack3.Class1 & Pack1.Pack2.Pack4.Class2

Pack4中,我们可以通过以下两种方式访问​​Class1Pack3.Class1Pack2.Pack3.Class1Pack1.Pack2.Pack3.Class1,其中最后一个将是完全合格的名称。

  1. 字段访问表达式是限定名的子类型,但顾名思义,它是用来访问字段的

因此,限定名称可以引用 Packge、Class、Interface 而不是字段,而字段访问表达式将仅引用字段

引用: http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.11 http://docs.oracle.com/javase/specs/jls/se7/html/jls-6.html#jls-6.5.6.2

关于java - 限定名称和字段访问表达式有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15354816/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com