Questions tagged [kotlin-reflect]

121 questions
2
votes
0 answers

How to include kotlin-reflect.jar in the classpath

I am trying to call someObject::class.annotations but get an error in runtime: Exception in thread "main" kotlin.jvm.KotlinReflectionNotSupportedError: Kotlin reflection implementation is not found at runtime. Make sure you have kotlin-reflect.jar…
Guy Or
  • 91
  • 1
  • 5
2
votes
0 answers

Transform nested data class to single level Map in Kotlin

Basically I have a data class like data class House( val bedroom: Bedroom, val livingroom: Livingroom ) data class Bedroom( val bed: String, val pillows: List ) data class Livingroom( val sofa: String, val tv: String ) I…
YIWEN GONG
  • 141
  • 1
  • 10
2
votes
1 answer

when is kotlin reflect lib necessary?

In the docs ( https://kotlinlang.org/docs/reference/reflection.html ) it is not mentioned what features of the reflection api are included in the reflection library. I can do basic reflection (listing members,parameters,etc) without explicitly…
IulianT
  • 350
  • 1
  • 3
  • 13
2
votes
1 answer

kotlin reflect crash , setting minifyEnabled to true . KotlinReflectionInternalError: Property 'xxx' not resolved in class 'xxx'

error log Process: com.sjianjun.test.kotlin.delegate, PID: 23730 kotlin.reflect.jvm.internal.KotlinReflectionInternalError: Property 'delegateTest' (JVM signature: getDelegateTest()Ljava/lang/Object;) not resolved in class…
SJJ
  • 417
  • 4
  • 5
2
votes
1 answer

Call a function with default parameter values using reflection

Consider an interface: interface Foo { fun func(argWithDefault: String = "default") } and its (minimal) implementation: class FooImpl() : Foo { override fun func(argWithDefault: String) { println(argWithDefault) } } I'm trying…
SpaceBison
  • 2,525
  • 1
  • 21
  • 38
2
votes
2 answers

KClass::memberExtensionFunctions always be empty

Code import kotlin.reflect.full.* class FooBar(val bar: String) fun FooBar.baz(): Unit {println(this.bar)} fun main(args: Array) { FooBar::class.declaredMemberExtensionFunctions.forEach { println(it) } …
jilen
  • 5,633
  • 3
  • 35
  • 84
2
votes
0 answers

Getting unresolved reference error in Kotlin Android Library Project

I am getting unresolved reference error in Kotlin Android Library project. 1.) standard_kotlin_lib.jar --> contains: Kotlin classes, META-INF/standard_kotlin_lib.kotlin_module 2.) A.aar --> compiles only standard_kotlin_lib.jar file. After…
2
votes
1 answer

Error when use callBy on a function with default parameters in Kotlin

I try to call a function with default parameters values without put parameters in Kotlin. For example: class Test { fun callMeWithoutParams(value : Double = 0.5) = value * 0.5 fun callIt(name: String) = this.javaClass.kotlin …
OlivierWah
  • 43
  • 1
  • 6
2
votes
0 answers

Kotlin Delegate with MultiDex on Android below 21

I have the following Delegate... fun integerPref(initialValue: Int) = object : ObservableProperty(initialValue) { override fun afterChange(property: KProperty<*>, oldValue: Int, newValue: Int) { getSharedPreference(INTEGER_PREF,…
1
vote
1 answer

KotlinReflectionNotSupportedError in Compose Preview

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. However, when I use reflection within a Composable…
mexes
  • 117
  • 7
1
vote
1 answer

Get the annotation variable and its type of a data class

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, @SerializedName("is_free") @ColumnInfo(name="is_free") var…
Saneen K P
  • 303
  • 1
  • 8
1
vote
0 answers

method toString throws KotlinReflectionInternalError

Why calling method toString() on function reference results in an error KotlinReflectionInternalError fun main() { fun foo(){} ::foo.toString() } output: Exception in thread "main" kotlin.reflect.jvm.internal.KotlinReflectionInternalError:…
Almir Burnashev
  • 179
  • 1
  • 6
1
vote
0 answers

Does Dagger support multibinding with KClass<*> type?

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, @JvmSuppressWildcards KSerializer<*>> // #2…
beigirad
  • 4,986
  • 2
  • 29
  • 52
1
vote
2 answers

Get Kotlin class from string a call a method in it

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() { fun test(): String { return "Do things B…
1
vote
1 answer

How to get only declared members (not inherited) with Kotlin Reflection?

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 free, which: Returns an array containing Method…
Miguel Gamboa
  • 8,855
  • 7
  • 47
  • 94