kotlinfunction-referenceconstructor-reference

Are there constructor references in Kotlin?


In Java we have the Class::new syntax for constructor references. I know, there are callable references for methods, but how about constructors? A typical use case for me would be factories.


Solution

  • You can get a function instance for a constructor by simply using ::ClassName, as if it were a factory function.