Skip to content

hidden and shadow in java

Posted on:July 10, 2023 at 03:02 PM



shadow 会和几个词相关:

原则: 在使用simple name的情况下 , scope 里面的会shadow scope外面的

If the class declares a field with a certain name, then the declaration of that field is said to hide any and all accessible declarations of fields with the same name in superclasses, and superinterfaces of the class.

15.11. Field Access Expressions

6.2 Names and Identifiers A name is used to refer to an entity declared in a program. There are two forms of names: simple names and qualified names. A simple name is a single identifier. A qualified name consists of a name, a ”.” token, and an identifier

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, provided it is not shadowed (§6.4.1)

6.4.1 Shadowing 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.