What is Scala equivalent of Java's static block ?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Code in the constructor (that is, the body) of the companion object is not precisely the same as code in a static initialiser block of a Java class. In the example below, I create an instance of A, but the initialization does not occur.
To trigger construction of the companion object when the first instance of the class is created, you could access it from the class constructor.
In many circumstances, the difference would not matter. But if you are launching missiles (or other side effects), you might care!