问题标签 [kotlin-reflect]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
679 浏览

kotlin - 如何获取 KmutableProperty i Kotlin 的容器?

val prop:KMutableProperty1<<A,Any>>在 A 类中有一个字段 x,我可以通过它获取字段名称,prop.name但是如何获取它的容器类名称 (A)?

0 投票
1 回答
985 浏览

android - Kotlin 按当前注释类过滤 memberProperties

我有一个在Any类型上运行的扩展方法。在该扩展方法上(其中this指的是目标实例),我正在尝试根据注释存在来过滤 memberProperties。

it.annotations总是大小为 0

实例上的变量声明示例: @ValidComponent var x: SomeType = constructorParam.something@ValidComponent lateinit var x: SomeType

0 投票
1 回答
132 浏览

reflection - memberProperty returnType 超类的类型检查失败

我有一个对象的实例,我会扫描它以查找附加了正确注释的 memberProperties。然后,我想根据它们的返回类型进行过滤。例如,如果声明如下:class AutoValidatedThing : AutoValidatedUserInputComponent {...}并且目标实例包含 a @ValidComponent val someProperty: AutoValidatedThing = ...,我希望将somePropertyas aAutoValidatedUserInputComponent放在以下代码块的末尾:

it.returnType is AutoValidatedUserInputComponent总是返回 false。

AutoValidatedUserInputComponent是一个简单的界面:

0 投票
1 回答
741 浏览

android - Proguard 使用 kotlin-reflect 为所有 INSTANCE 字段生成注释

我已将 kotlin-reflect 库添加到我的 Android 项目中,现在 Proguard 正在生成数百行注释,列出所有具有名为 字段的类INSTANCE,其中当然包括每个 Kotlin object

这只是 Proguard 输出的一小部分:

如您所见,它既包括我自己的MySingleton类,也包括来自 Kotlin 标准库的许多类,并且它也可以在任何其他库中找到这些字段(如果存在)。

0 投票
3 回答
5171 浏览

android - Kotlin - Call class method from object

Will try to keep this as concise as possible...

I would like to have a method in my MainActivty class, say updateUI().

I have another file that is an object called FBManager. That object essentially holds "static" firebase access methods.. let's say signInUser()

From the Activity I call FBManager.signInUser()... It does some logic and moves through 2 private methods and at the last private method, I would like to essentially call MainActivity.updateUI()…</p>

This can't be done as kotlin doesn't have static methods and can't make updateUI() static. MainActivity().updateUI() compiles but is incorrect and don't want to instantiate a new MainActivity. Lastly, I thought of passing the activity into the first constructor like FBManager.signInUser(this)... But after signInUser(), it goes to an override method that can only take a bundle as an optional input (and I don't believe you can put activities into a bundle), thus I can't pass the activity reference to the final private method.....

Edit: Further elaboration

Apologies for layout... Typing on my phone...

-end edit-

I hope all that makes sense as I'm new to programming and find it difficult to explain my problems (since if I truely understood them I could come up with a solution..)

So as per the title, is there any other way to do this... To call a method in MainActivity from an object FBManager?

0 投票
0 回答
69 浏览

kotlin - 如何通过反射获取 Kotlin Collection<*> 信息?

有没有办法知道收藏信息?

0 投票
1 回答
1227 浏览

android - 无法加载类'kotlin.reflect.KDeclarationContainer'.android studio 3.1.4

我是 kotlin 的新手,在构建项目中逐步在 android 中安装 kotlin 时,我得到了这个错误,搜索了很多关于如何解决这个问题的问题,但没有解决任何解决方案,比如使缓存/重置无效,请帮助我

0 投票
1 回答
1290 浏览

reflection - 获取可为空类型的类

我正在尝试匹配String?Kotlin 反射练习中可为空的类型:

唉,它因错误而失败,Type in a class literal must not be nullable, for String?::class

0 投票
1 回答
2398 浏览

reflection - How to set val property with Kotlin reflection?

I would like to return a copy of a class with a different value assigned to a val property.

if age was a var then I could do it like follows:

0 投票
1 回答
51 浏览

reflection - 泛型函数有效,但泛型类不行?

我想要一个通用的类KProperty1,我可以为一个函数做这个,但不是一个类: