gpt4 book ai didi

kotlin - 怎么把Class #cast方法从Java转换成Kotlin?

转载 作者:行者123 更新时间:2023-12-02 12:39:57 24 4
gpt4 key购买 nike

我想从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?

怎么做?

最佳答案

您可以使用Class<T>属性访问java实例

这应该工作:toClass.java.cast(from)

关于kotlin - 怎么把Class <T> #cast方法从Java转换成Kotlin?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36410955/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com