Bernhard
03/18/2024, 11:29 AMSam
03/18/2024, 11:37 AMFoo.something
than have a global property called somethingToDoWithFoo
. Of course companion objects aren't really a great solution to that problem, hence https://youtrack.jetbrains.com/issue/KT-11968. If those proposals end up being implemented I can't see there being much use for companion objects anymore.Bernhard
03/18/2024, 11:41 AMJoffrey
03/18/2024, 2:34 PMcompanion object
is an object
, and as such it can implement interfaces, such as factories. In that sense, the fact that the companion object has the name of the class is interesting.Bernhard
03/18/2024, 2:35 PMJoffrey
03/18/2024, 2:35 PMephemient
03/18/2024, 2:41 PMephemient
03/18/2024, 2:44 PMkotlinx.serialization.json.Json
, for example, is not meant to be a type directly instantiable by the user, for binary compatibility evolution reasons. the name refers to a builder function for an abstract class, and also that class's companion object which is a default instanceephemient
03/18/2024, 2:47 PM