Why does Eclipse require me to set (arbitrary) brackets in java code?

后端 未结 5 1200
-上瘾入骨i
-上瘾入骨i 2021-01-29 11:56

I am currently trying to figure out how to use Eclipse to program Escape models in java. I am quite new to Escape and Eclipse, and it has been a while since I programmed in java

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-29 12:03

    This has nothing to do with your IDE. Java does not allow statements at class level, it does however allow initializers at class level.

    {foo();}
    

    This is an instance initializer, it will be copied into all constructors by the compiler.
    (See Java Tutorial > Initializing Fields)

    In Java, you can write statements in

    • a method
    • a constructor (which is a special kind of method)
    • an initializer block (static or instance)

    but nowhere else.

提交回复
热议问题