Multiple open and close curly brackets inside method. - Java

前端 未结 2 1614
抹茶落季
抹茶落季 2020-12-05 14:22
 public class MyTestClass {

    public static void main(String[] args) {
        new MyTestClass().myMethod();
    }

    public void myMethod(){
        {
                 


        
2条回答
  •  粉色の甜心
    2020-12-05 14:45

    public void stuff() {
      int i = 48;
    
      { 
        int i = 21;
        System.out.println(i); // prints 21
      }
      System.out.println(i); // prints 48
    }
    

    Basically, it's a way to create scopes smaller than entire function... Benefit?.. have the people stare at your code longer before they understand it... IMO it's bad style and should be avoided

提交回复
热议问题