How to instantiate a new instance of generic type

后端 未结 2 816
温柔的废话
温柔的废话 2021-01-01 16:38

In C# you can place a new constraint on a generic to create a new instance of the generic parameter type, is there an equivalent in Kotlin?

Right now my work aroun

2条回答
  •  悲哀的现实
    2021-01-01 17:16

    Currently, that's not possible. You can give a thumbs-up for the issue https://youtrack.jetbrains.com/issue/KT-6728 to vote for the addition of this feature.

    At least, you can leave out the generic type because Kotlin can infer it:

    someMethod(::MyClass)
    

提交回复
热议问题