In Kotlin, is it possible to have a factory function that instantiates a class with a private constructor?
My goal is to forcefully use the factory function that will be used, and to prevent instantiation through the class constructor.
Example:
// factory function, valid val myInstance = myClassOf() // class instantiation, invalid val myInstance = MyClass()
I am trying to simulate the behavior of some built-in factory functions, such as intArrayOf() , for example.
// works val myIntArray = intArrayOf() // not possible as IntArray has a private constructor val myIntArray = IntArray()
source share