gpt4 book ai didi

reflection - 不在JVM上运行时,如何通过名称获取对Kotlin KClass的引用?

转载 作者:行者123 更新时间:2023-12-02 12:55:07 25 4
gpt4 key购买 nike

定位Java语言时,本地java.lang.Class.forName()不可用。在这些环境中如何获得KClass

最佳答案

就像 Kotlin documentation所说:

At this time, JavaScript does not support the full Kotlin reflection API. The only supported part of the API is the ::class syntax which allows you to refer to the class of an instance, or the class corresponding to the given type. The value of a ::class expression is a stripped-down KClass implementation that only supports the simpleName and isInstance members.



这是示例:
val a = A()

print(a::class.simpleName) // Obtains class for an instance; prints "A"
print(A::class.simpleName) // Obtains class for a type; prints "B"

关于reflection - 不在JVM上运行时,如何通过名称获取对Kotlin KClass的引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44648168/

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