
It cannot be defined inside an inner class.

However, in Kotlin we can handle this scenario and you’ll be able to call its members with the same syntax as calling static methods - fields in Java/C# and hence can create Singleton class in Kotlin.ġ: Object Decleration (Singleton Pattern)Ģ: Companion Objects (Static) Method 1 - Object Decleration (Singleton Pattern): So, how can we create singleton class in Kotlin? Since, Kotlin doesn’t have static member for class, it’s mean that you can’t create static method and static variable in Kotlin class.

In most cases, it’s recommended to simply use package-level functions instead. In Kotlin, unlike Java or C#, classes do not have static methods. Most of the programming language have concepts where classes can have static members - fields this means that only one instance of that static member is created which is shared across all instances of the class without an instance of their containing class. Kotlin - Static Member-Fields and Singletons
