抱歉,如果这是一个愚蠢的问题,Kotlin 对我来说仍然是新手,而且我不熟悉语法“类型”,所以发现很难找到解决方案。
fun Any?.test(): Any?
{
return this
}
"test string".test() // implicit string is now type of "Any"
"test string".test().substring() // what i'm trying to achieve
我基本上希望类扩展方法返回它自己的实例,所以我仍然可以按照示例的底线对其进行操作
原谅例子的粗鲁,被简化了