Companion is a singleton. Static methods are visib...
# announcements
m
Companion is a singleton. Static methods are visible through subclasses, companion objects’ methods are not. Static methods are procedural, companions are object-oriented.
m
I'm not sure there is any use of static methods being visible through subclasses except for confusing readers of the code using them like that.
m
There may be some utility static methods, but one may think they are overridable, which is confusing.
m
Ok. There is one use: having your own subclass of assertj's
Assertions
and *-importing it to get all functions.
m
First way (subclassing) is similar to declaring constants in interface and implementing it (so constants becoming visible through class which breaks encapsulation). Importing is better, and Kotlin allows it too.