local scope in Java

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

    Local variable shadowing is prohibited in Java on purpose (see this answer).
    The idea is that this helps decreasing bugs.

提交回复
热议问题