简体   繁体   English

Java文档变量范围

[英]Java doc for Scope of variables

Can anyone guide me to the java documentation for the scope of the variables . 谁能指导我了解有关变量范围的Java文档。 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 . 我想看一下Java文档中有关Java 8中的类变量和成员变量的信息,但找不到它。 Please guide me through it . 请指导我。 Thanks in advance. 提前致谢。

You need Java Language Specification not Java docs. 您需要Java语言规范,而不是Java文档。
Here's the link for it https://docs.oracle.com/javase/specs/jls/se8/html/index.html 这是它的链接https://docs.oracle.com/javase/specs/jls/se8/html/index.html

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". 您也许可以找到一个说明更加用户友好的教程,但是标识符范围的规范文档可以在Java语言规范中找到,特别是在第6.3节 “声明的范围”中。

The relevant statements concerning variables are: 有关变量的相关声明为:

  • 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. 由类类型C(第8.1.6节)声明或继承的成员m的声明的范围是C的整个主体,包括任何嵌套的类型声明。
  • 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. 在接口类型I(第9.1.4节)中声明或继承的成员m的声明的范围是I的整个主体,包括任何嵌套的类型声明。
  • 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. 块中的局部变量声明的范围(第14.4节)是该声明在其中出现的其余部分,从其自身的初始化程序开始,并在该局部变量声明语句的右侧包括其他任何声明符。
  • The scope of a local variable declared in the ForInit part of a basic for statement (§14.14.1) includes all of the following: 在基本for语句(第14.14.1节)的ForInit部分中声明的局部变量的范围包括以下所有内容:

    • Its own initializer 它自己的初始化器

    • Any further declarators to the right in the ForInit part of the for statement for语句的ForInit部分右侧的任何其他声明符

    • The Expression and ForUpdate parts of the for statement for语句的Expression和ForUpdate部分

    • The contained Statement 包含的声明

  • The scope of a local variable declared in the FormalParameter part of an enhanced for statement (§14.14.2) is the contained Statement. 在增强的for语句(第14.24.2节)的FormalParameter部分中声明的局部变量的范围是所包含的Statement。

  • 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语句(第14.20节)的catch子句中声明的异常处理程序的参数范围是与catch关联的整个块。

  • 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. 在try-with-resources语句的ResourceSpecification中声明的变量的范围(第14.20.3节)从该声明的右边开始,在ResourceSpecification的其余部分以及与try-with-resources语句关联的整个try块中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM