Java文档变量范围 [英] Java doc for Scope of variables

查看:99
本文介绍了Java文档变量范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以向我介绍Java文档中有关变量范围的内容. 我想看一下Java文档中有关Java 8中的类变量和成员变量的信息,但找不到它. 请指导我. 预先感谢.

Can anyone guide me to the java documentation for the scope of the variables . I would like to have a look at the java documentation for the class variables and member variables in java 8 but can't find it . Please guide me through it . Thanks in advance.

推荐答案

您也许可以找到带有更用户友好描述的教程,但是标识符范围的规范文档可以在Java语言规范中找到,特别是在第6.3 ,声明的范围".

You might be able to find a tutorial with a more user-friendly description, but the canonical documentation of identifier scope can be found in the Java Language Specification, specifically in Section 6.3, "Scope of a Declaration".

有关变量的相关陈述是:

The relevant statements concerning variables are:

  • 在类类型C(第8.1.6节)中声明或继承的成员m的声明的范围是C的整个主体,包括任何嵌套的类型声明.
  • 在接口类型I(第9.1.4节)中声明或继承的成员m的声明的范围是I的整个主体,包括任何嵌套类型声明.
  • 块中的局部变量声明的范围(第14.4节)是该声明在其中出现的其余部分,从其自身的初始化程序开始,并在局部变量声明语句的右侧包括其他任何声明符./li>
  • 在基本for语句(第14.14.1节)的ForInit部分中声明的局部变量的范围包括以下所有内容:

  • The scope of a declaration of a member m declared in or inherited by a class type C (§8.1.6) is the entire body of C, including any nested type declarations.
  • The scope of a declaration of a member m declared in or inherited by an interface type I (§9.1.4) is the entire body of I, including any nested type declarations.
  • The scope of a local variable declaration in a block (§14.4) is the rest of the block in which the declaration appears, starting with its own initializer and including any further declarators to the right in the local variable declaration statement.
  • The scope of a local variable declared in the ForInit part of a basic for statement (§14.14.1) includes all of the following:

  • 它自己的初始化程序

  • Its own initializer

for语句的ForInit部分右侧的任何其他声明符

Any further declarators to the right in the ForInit part of the for statement

for语句的Expression和ForUpdate部分

The Expression and ForUpdate parts of the for statement

包含的语句

在增强的for语句(第14.14.2节)的FormalParameter部分中声明的局部变量的范围是所包含的Statement.

The scope of a local variable declared in the FormalParameter part of an enhanced for statement (§14.14.2) is the contained Statement.

在try语句(第14.20节)的catch子句中声明的异常处理程序的参数范围是与catch关联的整个块.

The scope of a parameter of an exception handler that is declared in a catch clause of a try statement (§14.20) is the entire block associated with the catch.

在try-with-resources语句(第14.20.3节)的ResourceSpecification中声明的变量的范围是从声明开始,到ResourceSpecification的其余部分以及与try-相关的整个try块. with-resources语句.

The scope of a variable declared in the ResourceSpecification of a try-with-resources statement (§14.20.3) is from the declaration rightward over the remainder of the ResourceSpecification and the entire try block associated with the try-with-resources statement.

这篇关于Java文档变量范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆