Are there constructor references in Kotlin?

2019-01-17 19:23发布

问题:

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.

回答1:

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