Java doc for Scope of variables

萝らか妹 提交于 2019-12-13 09:00:19

问题


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.


回答1:


You need Java Language Specification not Java docs.
Here's the link for it https://docs.oracle.com/javase/specs/jls/se8/html/index.html




回答2:


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:

  • 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

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

    • The Expression and ForUpdate parts of the for statement

    • 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.

  • 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.

  • 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.



来源:https://stackoverflow.com/questions/39867972/java-doc-for-scope-of-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!