Why Can You Instantiate a Class within its Definition?

前端 未结 9 1853
无人共我
无人共我 2020-12-24 13:22

A coworker (who is very new to Java) stopped in today and asked what seemed like a very simple question. Unfortunately, I did an absolutely horrible job of trying to explain

9条回答
  •  清歌不尽
    2020-12-24 13:54

    Because code is compiled first, and executed later. All the compiler needs to know to validate that line is that a class named XCopy exists, and that it has a no-argument constructor. It doesn't need to know everything about the class.

提交回复
热议问题