local scope in Java

前端 未结 8 2019
轮回少年
轮回少年 2020-12-20 23:31

Why is it that curly braces do not define a separate local scope in Java? I was expecting this to be a feature common to the main curly brace languages (C, C++, Java, C#).<

8条回答
  •  一向
    一向 (楼主)
    2020-12-21 00:09

    They do define a separate local scope, but you still cannot mask local variables from a parent scope (but you can of course mask instance variables).

    But you can define new variables (with different names) and their scope will be limited to within the braces.

提交回复
热议问题