In Java, why have a code block with no keywords, just curly brackets

前端 未结 4 1056
感动是毒
感动是毒 2020-12-11 14:49

I\'m re-factoring some inherited code, but was stumped by the design decision and can\'t figure out the proper terms to google this. My predecessor would use blocks like thi

4条回答
  •  心在旅途
    2020-12-11 15:33

    Scope. Any variables declared in the block go out of scope after the block. It's useful to keep variables scoped minimally.

    Also, if you define an anonymous inner class, you use this syntax for the constructor.

提交回复
热议问题