local scope in Java

前端 未结 8 2052
轮回少年
轮回少年 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:05

    Blocks define a local scope, but don't allow you to redefine a variable with the same name as another variable in an outer local scope. If it did, there would be no way to access the "hidden" variable.

提交回复
热议问题