Questions tagged [kotlin-reflect]
121 questions
1
vote
1 answer
kotlin: How to get the field name which in Object?
I have a @ConfigurationProperties class, like ConfigProperty. I use it like
org.springframework.ui.Model#addAttribute("config1", configProperty.config1)
org.springframework.ui.Model#addAttribute("config2", configProperty.config2)
I don't want…

Cnfn
- 1,123
- 8
- 11
1
vote
1 answer
Generic function works, but generic class doesn't?
I would like a class that is a generic for KProperty1, I can do this for a function, but not a class:
import kotlin.reflect.KProperty1
data class Dog(val name: String, val age: Int)
fun > reflectionHelper(input: P) =…

Morgoth
- 4,935
- 8
- 40
- 66
1
vote
3 answers
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…

NicCoe
- 409
- 4
- 17
1
vote
1 answer
Proguard generating notes for all INSTANCE fields with kotlin-reflect
I've added the kotlin-reflect library to my Android project, and now Proguard is generating hundreds of lines of notes, listing all classes that have a field named INSTANCE, which of course includes every single Kotlin object.
Here's just a short…

zsmb13
- 85,752
- 11
- 221
- 226
1
vote
1 answer
Type check fails for memberProperty returnType superclass
I've got an instance of an object, which I scan for memberProperties that have a proper annotation attached on them. Then, I want to filter based on their return type.
For example if declaration is as follows: class AutoValidatedThing :…

ntakouris
- 898
- 1
- 9
- 22
1
vote
1 answer
Kotlin filter memberProperties by present annotation class
I've got an extension method running on Any type.
On that extension method (where this refers to the target instance), I'm trying to filter the memberProperties based on annotation presence.
this::class.memberProperties
.filter{…

ntakouris
- 898
- 1
- 9
- 22
1
vote
3 answers
How do I get container of KmutableProperty i Kotlin?
I have a val prop:KMutableProperty1<> of field x in class A, I can get field name by prop.name but how do I get its container class name (A)?

ssuukk
- 8,200
- 7
- 35
- 47
1
vote
1 answer
obtain class from nested type parameters in kotlin
I have a val built like this
val qs = hashMapOf ,Question>()
How can I obtain the class of ProfileModel.PersonalInfo from this variable?
In other words what expression(involving qs of course) should replace…

saiedmomen
- 1,401
- 16
- 33
1
vote
1 answer
ReflectKotlinClass not found in Spring Boot M7 with MongoDB
If you create a new Spring Boot project on start.spring.io with the Web and MongoDB module, add any @Document annotated class, and in addition upgrade the kotlin.version from 1.2.10 to 1.2.21 you get a NoClassDefFoundError:
Failed to execute goal…

Gregor
- 2,917
- 5
- 28
- 50
1
vote
1 answer
Check if class is a valid value for KParameter
Given the following example code
fun function(text: CharSequence) {
println(text)
}
val textParam = ::function.parameters[0]
val stringClass = String::class
How can I check if textParam accepts stringClass as a parameter?

Mibac
- 8,990
- 5
- 33
- 57
1
vote
1 answer
Check if function is extension
Given a KFunction how can I check if it's a extension function?
The only way I know is to check if function.extensionReceiverParameter returns null. Is there any other or a recommended way?

Mibac
- 8,990
- 5
- 33
- 57
1
vote
1 answer
Kotlin check if function requires instance parameter
If a KCallable is created using Any()::toString then when it's later referenced you don't need to pass that Any instance (when using call).
Though if it's created using Any::toString (not an instance of Any) it's required to pass an Any instance.…

Mibac
- 8,990
- 5
- 33
- 57
0
votes
0 answers
Why should load class from on demand modules(Dynamic modules) firstly in the callback of SplitInstallManager?
Recently, I'm doing a feature based on Dynamic Modules, and I want to load a class from dynamic modules. Since base app can't access class in dynamic module, I use direct reflection to do this. Below is my reflection code:
const val PROVIDER_CLASS=…

Mirai
- 13
- 3
0
votes
1 answer
How to get annotations of a variable in external method using Kotlin?
I'm starting with Kotlin reflection. I need to write a method in Kotlin that would take a variable (in this case lets say of type String) and return all annotations (if any) that are applied to that variable.
fun getAnnotations(variable: String):…

user21474430
- 3
- 1
0
votes
1 answer
Kotlin - return all properties that implement an interface and are annotated
I have a simple kotlin 1.7.10 program - I have an interface called Rule and property annotation called NextRule + 2 implementations like
import kotlin.reflect.KClass
interface Rule {
fun process(s: String):…

Clyde Barrow
- 1,924
- 8
- 30
- 60