What is the equivalent of Java Static methods in Kotlin?

Java

Video is ready, Click Here to View ×


Companion object in Kotlin
Unlike Java, Kotlin doesn’t have static members or member functions. Kotlin recommends to simply use package-level functions instead.
If you need to write a function that can be called without having a class instance but needs access to the internals of a class, you can write it as a member of a companion object declaration inside that class. By declaring a companion object inside our class, you’ll be able to call its members with the same syntax as calling…

Leave a Reply

Your email address will not be published. Required fields are marked *