How do I constrain a Kotlin extension function parameter to be the same as the extended type?

后端 未结 3 1446
遇见更好的自我
遇见更好的自我 2020-12-18 19:25

I want to write an extension method on a generic type T, where the matched type constrains a method parameter.

I want this to compile:

\"Hello\".thin         


        
3条回答
  •  春和景丽
    2020-12-18 20:05

    As far as I know, this is not possible in Kotlin 1.0. There are several issues in the tracker (first, second) about a similar use case, and the solution proposed in the first one is likely going to help here in the future as well.

提交回复
热议问题