java 规则解析_Java标识符解析规则

我认为您的意思不是搜索顺序.相反,我认为该规则适用:

6.5.5 Meaning of Type Names The meaning of a name classified as a

TypeName is determined as follows.

6.5.5.1 Simple Type Names If a type name consists of a single Identifier,

then the identifier must occur in the

scope of exactly one visible

declaration of a type with this name,

or a compile-time error occurs. The

meaning of the type name is that type.

在这种情况下,进口算作声明;参见JLS 6.1.但是,复杂的因素是影子规则(JLS 6.3.1),该规则说某些类型的声明(在这种情况下为类型)隐藏了现有的声明,而其他则没有.具体来说,“按需导入”(例如import java.util.*;或java.lang.*的隐式导入)不会遮盖其他声明.

例如

package foo;

import java.sql.Date;

import java.util.*; // import on demand: java.util.Date does not shadow java.sql.Date

import java.awt.*; // import on demand: java.awt.List does not shadow java.util.List

class Integer { // (foo.)Integer shadows java.lang.Integer

...

static class Integer { // (foo.Integer.)Integer shadows foo.Integer.

...

List t = ... // Compilation error, because there are currently two visible

// declarations of List (JLS 6.5.5.1)

}

}

另一个问题是,“单一类型导入”(如上面的import java.sql.Date;)会遮盖在同一包中声明的类型,并按需导入类型,但不会遮蔽通过另一个“单一”导入的其他类型. -type-import”(JLS 6.3.1).因此,例如,以下是编译错误:

import java.sql.Date;

import java.util.Date; // Compilation error

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值