Java Language Specification - Cannot understand 'BlockStatement'

前端 未结 5 1665
梦如初夏
梦如初夏 2021-02-20 00:06

I\'ve been examining the Java Language Specification here (instead I should be out having a beer) and I am curious about what a method can contain. The specification states a me

5条回答
  •  礼貌的吻别
    2021-02-20 00:52

    Oh yes you can declare a class inside a method body. :-)

    class A {
    
        public void doIt() {
            class B {}
            B b = new B();
            System.out.println(b.getClass());
        }
    
    }
    

提交回复
热议问题