Kotlin中有构造函数引用吗? [英] Are there constructor references in Kotlin?
本文介绍了Kotlin中有构造函数引用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Java中,构造函数引用具有Class::new
语法.我知道,方法有可调用的引用,但是构造函数呢?对我来说,典型的用例是工厂.
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.
推荐答案
只需使用::ClassName
即可获得构造函数的函数实例,就好像它是工厂函数一样.
You can get a function instance for a constructor by simply using ::ClassName
, as if it were a factory function.
这篇关于Kotlin中有构造函数引用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文