Are there constructor references in Kotlin?

KotlinFunction ReferenceConstructor Reference

Kotlin Problem Overview


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.

Kotlin Solutions


Solution 1 - Kotlin

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKirill RakhmanView Question on Stackoverflow
Solution 1 - KotlinIlya RyzhenkovView Answer on Stackoverflow