Semantic difference between object expressions and declarations

  • object expressions are executed (and initialized) immediately, where they are used;
  • object declarations are initialized lazily, when accessed for the first time;
  • a companion object is initialized when the corresponding class is loaded (resolved), matching the semantics of a Java static initializer.

https://kotlinlang.org/docs/reference/object-declarations.html#companion-objects

原文地址:https://www.cnblogs.com/ysmintor/p/8267980.html