如何将Class <T> #cast方法从Java转换为Kotlin?
我想从Java转换下面的代码:
Object from = ... Class<T> toClass = ... T result = toClass.cast(from);
到Kotlin:
Any? from = ... KClass<T> toClass = ... T result = // toClass.cast(from) - how to convert this line to Kotlin?
怎么做?
您可以使用java
属性访问Class<T>
实例
这应该工作: toClass.java.cast(from)
对于任何Java到Kotlin转换器,使用网站上提供的在线转换器。
http://try.kotlinlang.org/#/Examples/Longer%20examples/Maze/Maze.kt