如何将Class <t> #cast方法从Java转换为Kotlin?

时间:2016-04-04 19:12:07

标签: kotlin

我想从Java转换以下代码:

useAnt has been deprecated and is scheduled to be removed in Gradle 3.0. The Ant-Based Scala compiler is deprecated, please see https://docs.gradle.org/current/userguide/scala_plugin.html.
fork has been deprecated and is scheduled to be removed in Gradle 3.0. The fork option for the scala compiler is deprecated, please see https://docs.gradle.org/current/userguide/scala_plugin.html.

到Kotlin:

Object from = ...
Class<T> toClass = ...

T result = toClass.cast(from);

怎么做?

2 个答案:

答案 0 :(得分:4)

您可以使用Class<T>属性

访问java实例

这应该有效:toClass.java.cast(from)

答案 1 :(得分:0)

对于任何java to Kotlin转换器,请使用网站上提供的在线转换器。

http://try.kotlinlang.org/#/Examples/Longer%20examples/Maze/Maze.kt