Chinaunix首页 | 论坛 | 博客
  • 博客访问: 194585
  • 博文数量: 69
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 720
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-03 11:35
文章分类

全部博文(69)

文章存档

2011年(13)

2010年(46)

2009年(10)

我的朋友

分类: Java

2010-07-12 11:49:23

JLS100712Note on JLS, Ch6

 

@ http://zcatt.cublog.cn

 

Hist:

1007012, draft

 

 

 

Chapter6 Names(名字)

Every declaration that introduces a name has a scope.Access is a different concept from scope, access specifies the part of the program text within which the delcared entity can be referred to by a qualified name, a field access expression, or a method invocation expression.

 

Delcarations

A declaration introduces an entity into a program and includes an identifier that can be used in a name to refer to this entity:

1)      a package

2)      an imported type

3)      a class

4)      an interface

5)      a type variable

6)      a member of a reference type: a member class, a member interface, an enum constant, a field(a field declared in a class type, a constant field declared in an interface type, the field length which is implicity a member of every array type), a method( a method declared in a class type, a method declared in an interface type), a parameter(a parameter of a method or constructor of a class, a parameter of an abstract method of an interface, a parameter of an exception handler declared in a catch clause of a try statement), a local variable( declared in a block, and declared in a for statement).

 

Names and Identifiers

A name is used to refer to an entity declared in a program. Two forms of names: simple names and qualified names. A simple name is a single identifier. A qualified name consistent of a name, a ‘.’ token, and an identifier. In determining the meaning of a name, the context in which the name appears is taken into account.

 

Scope of a Declaration

The scope of a declaration is the region of the program within which the entity declared by the declaration can be referred to using a simple name. A declaration is said to be in scope at a particular point in a program if and only if the declaration’s scope includes that point.

 

Shadowing Declarations

Some declarations may be shadowed in part of their scope by another declaration of the same name, in which case a simple name cannot be used to refer to the declared entity. A declaration d is said to be visible at point p in a program if the scope of d includes p, and d is not shadowed by any other declaration at p.

Note that shadowing is distinct from hiding and obscuring.

 

Obscured Declarations

A simple name may occur in context where it may potentially be interpreted as the name of a variable, a type or a package. In which situations, a variable will be chosen in preference to a type, and a type will be chosen in preference to a package. So it is may somtimes be impossible to refer to a visible type or package declaration via its simple name. We say that such a declaration is obscured.

 

Members and Inheritance

 

The Members of Type Variables, Parameterized Types, Raw Types, and Intersection Types

 

The Members of a Package

 

The Member of a Class Type

The members of a class type are all of the following:

1)      members inherited from its direct superclass.

2)      members inherited from any direct superinterfaces

3)      members declared in the body of the class

Constructors and type variables are not members.

A class type may have two or more methods with the same simple name if the methods have signatures that are not override-equivalent. Such a method member name is said to be overloaded.

A class type may contain a declaration for a method with the same name and signature as a method that would otherwise be inherited from a superclass or superinterface. In this case, the method of the superclass or superinterface is not inherited. If the method not inherited is abstract, the new declaration is said to implement it. If the method is not abstract, then the new declaration is said to override it.  

 

The Members of an Interface Type

An interface may have two or more fields with the same simple name if they are declared in different interfaces and inherited. An attempt to refer to any such field by its simple name results in a compile-time error.

 

The Members of an Array Type

1)      the public final field length

2)      the public method clone

3)      all the members inherited from class Object except the clone method

 

Determining the Meaning of a Name

 

Access Control

If access is permitted, the accessed entity is said to be accessible. The accessibility is a static property that can be determined at compile time. It depends only on types and declaration modifiers.

 

Determining Accessibility

 

Fully Qualified Names and Canonical Names

 

Naming Convetions

 

REF

1.       JLS 3nd

2.       JVM 2nd
Locations of visitors to this page

阅读(861) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~