What is the difference between a qualified name and a field access expression?

From the JLS Details for Secure Access :

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

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

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

If access is via an access expression to the field E.Id, where E is the Primary expression or method call expression E.Id (...), where E is the primary expression, then access is allowed if and only if the type E is S or subclass S.

What is the difference between a qualified name and a field access expression?

+6
java jls
source share
2 answers

qualified name makes sense in terms of class name (think about it in terms of statics). where the expression for accessing the field is similar to defining the Fully Qualified Name as a reference for a specific class object, including method names.

Example:

 public class A { public static void method1() {//does something } } public class B { public int dummy; public void hello() { System.out.println("Hello!"); } } public class Main { public static void main(String[] args) { B b = new B(); b.dummy=1; b.hello(); } } 

here in the above classes if we say

 A.method1() 

it’s rather a qualified name, where

 b.hello(); b.dummy 

- more expressions for accessing the field.

0
source share

If the expression name is of the form Q.Id, then Q is already classified as a package name, type name, or expression name.

The value of the field access expression is determined using the same rules as for qualified names, but is limited by the fact that the expression cannot denote a package, class type, or interface type.

found the above text on oracle website.

so in simple words:

  • A qualified name means that it carries parental information in the declaration. eg. Pack1.Pack2.Pack3.Class1 and Pack1.Pack2.Pack4.Class2

in Pack4 , we can access Class1 in one of the following ways: Pack3.Class1 or Pack2.Pack3.Class1 or Pack1.Pack2.Pack3.Class1 , where the latter will be fully qualified.

  • a field access expression is a subtype of a qualified name, but as the name implies, it is intended to access a field

Qualified names can refer to Packge, Class, Interface, but not to fields, while a field access expression applies only to fields

REF: 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

0
source share

All Articles