I want to have functions that sit in classes (not polluting the global namespace) but are accessed statically (never creating an object in which they reside). Proposed solution:
object A {
@JvmStatic
fun mkdir() {}
}
Is this a good solution or will it inevitably create an object? Which pattern should I use?
objectkeyword give you a hint about whether this uses an object? Also, have you checked the many existing questions about statics in Kotlin?companion objects areobjects. Anobjectdeclaration in Kotlin is translated into a regular class with a statically initialized unique instance. With@JvmStatic, the methodmkdirwill be static, but the unique instance will be created nevertheless when the class is initialized. What exactly are you concerned about with the creation of a singleton?