Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
39 views

gradle -> libs.version.toml [versions] ... kotlin = "2.1.0" [libraries] ... kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }...
u zh's user avatar
  • 33
3 votes
0 answers
89 views

I am working with a Java agent that is adding an annotation dynamically to a class file. When this class file is a Kotlin class, and if it is investigated by Kotlin reflection, the annotation does not ...
Rafael Winterhalter's user avatar
0 votes
0 answers
54 views

I have tried the answer in this post but I still get the error in my Kotlin Android project. Here is how my code looks like: interface BaseServiceScope { suspend fun resolveState2(intent: Intent?)...
exbuddha's user avatar
  • 633
2 votes
1 answer
171 views

How can I set property value for classes with object keyword using kotlin.reflect API? I was hoping that this is analogous to setting values in regular classes, however, this is not the case. When ...
Marcoral's user avatar
0 votes
0 answers
32 views

I am trying to read the annotations of a value that I pass to a function. I have an annotation defined as: @Retention(AnnotationRetention.SOURCE) @Target(AnnotationTarget.EXPRESSION) annotation class ...
exbuddha's user avatar
  • 633
0 votes
1 answer
94 views

I'd like to retrieve a property if the referenced object has one. (I have a more complex use case, but this demonstrates the problem nicely). It appears, the only way to do this is by breaking ...
Kurt's user avatar
  • 595
0 votes
1 answer
119 views

How to use Java or Kotlin reflection to access the value of a private variable in the Main.kt file? package com.example private val myName = "abc" fun main() { println(myName) }
Mahozad's user avatar
  • 26.4k
0 votes
1 answer
53 views

I am trying to use kotlin.reflect to get the names of variables in this array all. Then iterate over the array and get the name of each variable a, b, c. But well its not working and im not sure how ...
cuttlefish's user avatar
2 votes
1 answer
325 views

Is there a way to get a Kotlin KType from a java.lang.reflect.Type? Background: I'm working on some code that gets properties/fields from a class and passes them to methods (think JUnit 4 Theories for ...
Cobra1117's user avatar
  • 1,452
1 vote
1 answer
271 views

I'm working with a third-party library that has a function which expects an argument of type KProperty1<T, V>, and casts it to an instance of CallableReference internally. I need to acquire a ...
Albert Bill's user avatar
0 votes
1 answer
111 views

I want to implement a function that compares two objects of the same type based on their Comparable properties, such as: fun <T:Any> reflectCompare(a: T, b: T) : Int { a::class ....
Miguel Gamboa's user avatar
1 vote
1 answer
301 views

I have a method reference (represented by the kotlin.reflect.KFunction0 interface). What I would like to do is to get the receiver object of the method reference. For example: data class MyClass(val ...
Martin Häusler's user avatar
0 votes
1 answer
124 views

I have the following simple class structure: package qwerty import kotlin.reflect.full.declaredMemberProperties class UserSet( var user1: User, var user2: User? = null, ) class User( ...
RedMurloc's user avatar
  • 157
1 vote
0 answers
94 views

I am trying to call a function in Kotlin file from a java code but unable to do so, I can easily call the function from kotlin using A::a where A is the data class and 'a' is its property I have a ...
Ankush Tiwari's user avatar
2 votes
1 answer
297 views

I was trying to convert a Map<String, Any> to data class instance: data class Person( val name: String, val age: Int, val weight: Double?, ) fun test() { val map = mapOf( ...
zwlxt's user avatar
  • 385
0 votes
1 answer
343 views

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 ...
user21474430's user avatar
0 votes
1 answer
70 views

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(...
Clyde Barrow's user avatar
  • 2,164
0 votes
1 answer
349 views

There is such a function public inline fun <reified W : ListenableWorker> PeriodicWorkRequestBuilder( repeatInterval: Duration ): PeriodicWorkRequest.Builder { return PeriodicWorkRequest....
SageJustus's user avatar
  • 1,212
2 votes
1 answer
429 views

I have defined the Kotlin reflection dependency in my Gradle file as follows: implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" Within the App, reflection works just fine. ...
mexes's user avatar
  • 137
0 votes
1 answer
911 views

I'm having problem with Kotlin poet PropertySpec object. Because i can't provide List<String> to the PropertySpec builder. Help please. PropertySpec.builder("services", List<String&...
Jamshed Alam Qaderi's user avatar
1 vote
1 answer
497 views

I have a data class in kotlin , which is also a Room entity. Eg : data class Pack( @ColumnInfo(name = "name") @SerializedName("name") var name:String, @...
Saneen K P's user avatar
6 votes
2 answers
496 views

Why calling method toString() on function reference results in an error KotlinReflectionInternalError fun main() { fun foo(){} ::foo.toString() } output: Exception in thread "main" ...
Almir Burnashev's user avatar
2 votes
1 answer
920 views

Currently, I’m creating a new SDK that contains sensitive fields that shouldn’t be read by the consumers (Think Credit Card Number field) and I’m using Jetpack Compose to create the forms, my question ...
Mahmoud Elshamy's user avatar
0 votes
3 answers
850 views

I have simple Kotlin code in an existing Java project class A(val p: Int) fun main() { println("Hello World") println(A::javaClass) println(A::p) } However, this throws an ...
user1064504's user avatar
1 vote
1 answer
334 views

I have a method inside a class: class Foo { fun bar() } And I want to pass the method bar to a third-party library method that takes a java.lang.reflect.Method argument: fun baz(Method method) ...
k314159's user avatar
  • 12.4k
3 votes
1 answer
255 views

I want to create a String representation of the path from a root element A through it's declared member properties, until I get to a specific leaf element, using Kotlin member references. To clarify, ...
fiftyone_51's user avatar
2 votes
1 answer
203 views

I have a KeyMap like this: @Target(AnnotationTarget.FUNCTION) @MapKey annotation class JsonSerializerKey(val value: KClass<*>) and want to provide them as: // #1 doesn't work Map<KClass<*&...
beigirad's user avatar
  • 5,882
0 votes
1 answer
933 views

I'm trying to use Kotlin Reflection to generate JFrames from Classes with their members. I have created a couple Annotations, some of them are present at runtime and some are not. Component Annotation:...
Marconymous's user avatar
0 votes
0 answers
989 views

Last time I did this the project ran just fine but I am getting these errors now, I tried installing kotlin-reflect but still it didn't work. It doesn't recognise lazy and with either and I simply don'...
Antonio Roldan's user avatar
0 votes
2 answers
2k views

I have 2 simple classes in kotlin package com.sample.repo class SampleClassA() { fun test(): String { return "Do things A way" } } package com.sample.repo class SampleClassB(...
Bhaskar Devgon's user avatar
1 vote
1 answer
975 views

Is there any way to get only the declared members of a class (not inherited) with Kotlin Reflection? Something equivalent to getDeclaredMethods(), or ...Fields(), in Java, but for members and JVM ...
Miguel Gamboa's user avatar
0 votes
1 answer
860 views

I want to find memberProperties that are not other classes I declared. For example data class X(val other: String) data class Y(val str: String, val y: X?) I want to filter() my Y::class....
zaitsman's user avatar
  • 9,590
2 votes
1 answer
1k views

Given a domain class with a parameterless constructor, how do we get a reference to that constructor through the Reflection API? Consider for example a Student data class, such as: data class Student(...
Miguel Gamboa's user avatar
4 votes
0 answers
908 views

Currently using Moshi with Retrofit but need to look back as I noticed I am not implementing it right and confused when to add kotlin-reflect in the dependencies. According to README The reflection ...
Bitwise DEVS's user avatar
  • 3,851
3 votes
0 answers
1k views

Kotlin specification states basic types as "Some types can have a special internal representation - for example, numbers, characters and booleans can be represented as primitive values at runtime&...
Miguel Gamboa's user avatar
1 vote
1 answer
775 views

I'm trying to get the class that owns a companion object so I can create loggers with inline technique inside a companion object but referencing the main class that is being logged and not the ...
Polyana Fontes's user avatar
1 vote
1 answer
2k views

Data class data class A( var data: List<Data> ) { data class Data( var key: String, var count: Long = 0, var sub: List<Data>? = null ) } A class data ...
nkhcode's user avatar
  • 87
3 votes
0 answers
248 views

In my app I’ve recently updated Kotlin from 1.5.31 to 1.6.10. Since then a specific function that uses reflection (kotlin-reflect) stopped working as expected. It works perfectly fine in 1.5.31. Now, ...
MatJB's user avatar
  • 165
5 votes
1 answer
5k views

I have a package with some data classes and I'm trying to access the constructor at runtime using Kotlin reflection clazz.primaryConstructor, Everything is working as expected but when I enable R8, ...
Ahmad Mahmoud Saleh's user avatar
1 vote
1 answer
1k views

I am trying to access the companion object of an unknown class with a known interface, given an instance of the class. Code below: class AccessTest() { companion object { val prop = 5 }...
Will Chen's user avatar
  • 692
1 vote
1 answer
1k views

I want to have for example: class Foo { fun doSomething(arg1: String, arg2: String, arg3: Boolean) } class FooDelegate { //different fun name fun execute by Foo::doSomething } Either with ...
htafoya's user avatar
  • 19.4k
0 votes
1 answer
204 views

If I have a Kotlin class like the following: data class Foo( val count: AtomicInteger ) { init { count.incrementAndGet() } } How do I determine that this class has an init block ...
David Rawson's user avatar
  • 21.1k
0 votes
0 answers
165 views

What I'd like to do is use Kotlin reflection to make a copy of a class and set all of it's properties optional/nullable. E.g. fun looseClass(schema: KClass<*>): KClass<*> { ...
godzsa's user avatar
  • 2,455
0 votes
2 answers
831 views

I'm trying to access the delegate of the property (id) of a class (FooImpl). The problem is, this class implements an interface (Foo), and the property in question overrides a property of this ...
Kolja's user avatar
  • 1,247
1 vote
2 answers
954 views

Is there a simple method I can use to list all of the properties in a class that don't implement a custom getter? For example: class Person(val name: String, val age: Int) { val signature: ...
Andrzej Zabost's user avatar
0 votes
1 answer
1k views

I'm having a hard time trying to get a private method in Kotlin using reflection in order to pass it as a parameter to a higher order function, here is what I got and what I need to do: The function ...
Alejandro Casanova's user avatar
1 vote
0 answers
2k views

Background I'm trying to create some Teamcity configuration using Kotlin. I'm using a Maven in Intellij when testing the generation of the Teamcity, although I get the same result by using the ...
MrSpaceman's user avatar
2 votes
2 answers
3k views

I'm learning Kotlin and I have problem with this code: import kotlin.reflect.* fun main(args: Array<String>) { val lst = listOf(1,2,3,45,5,6,7,8) val mapped = lst.map {Data(::isEven,it)}...
Jan Válek's user avatar
0 votes
1 answer
423 views

I'm trying to create a function that returns any data class object setting it's property values with its property names (if all strings) without changing it's default values I have an example on how ...
julioribeiro's user avatar
  • 1,753
0 votes
1 answer
2k views

I have to check if a particular variable inside a kotlin data class has an annotation present or not. Annotation class annotation class Test( val identifier: String ) Data class data class Player(...
matrixguy's user avatar
  • 306