enighma
04/18/2023, 5:10 PM@JvmField
annotation, so maybe that's what makes the above not work?Emil Kantis
04/27/2023, 10:21 PMKCallable
with default parameters, without explicitly supplying those parameters?dewildte
08/25/2023, 8:02 PM::functionReference.name
?
More details in the 🧵Settingdust
09/10/2023, 3:14 AMkotlin1910.kotlin1910_builtins
.
Then, I added custom transformers for avoiding shadow
relocate the .kotlin_builtins
constant in kotlin reflect.
And relocate the kotlin/kotlin.kotlin_builtins
to kotlin1910/kotlin1910.kotlin_builtins
But the reflect can't find the builtin class AssertionError: Built-in class kotlin1910.Any is not found
Zoltan Demant
10/10/2023, 6:09 AMinterface Dispatcher<T : Request<R>, R> {
val type: KClass<T>
suspend fun dispatch(
request: T,
): R
}
nikolaymetchev
11/23/2023, 4:29 PMv79
11/23/2023, 8:43 PM(kType.classifier as KClass<*>).constructors
and that requires kotlin-reflect. Any alternatives?martmists
12/24/2023, 4:13 PMSean Proctor
02/26/2024, 11:49 PMColton Idle
03/09/2024, 7:01 AMval field = CryptoFormat::class.java.getDeclaredField("NON_RAW_PREFIX_SIZE")
field.isAccessible = true
val modifers = field.javaClass.getDeclaredField("modifiers")
modifers.isAccessible = true
modifers.setInt(field, field.modifiers and java.lang.reflect.Modifier.FINAL.inv())
field.setInt(null, 2000)
val newValue = CryptoFormat.NON_RAW_PREFIX_SIZE
println("NON_RAW_PREFIX_SIZE is now: $newValue")
Error: java.lang.NoSuchFieldException: modifiers
Emil Kantis
03/15/2024, 9:19 AMString
? e.g.
fun add(a: Int, b: Int) {
println("${a::name} is $a") // a is 5
}
Johannes Wirde
05/15/2024, 9:43 AMKClassifier.createType
throws on me because the internal descriptor is null/faulty (found at core/reflection.jvm/src/kotlin/reflect/full/KClassifiers.kt:48
, I'm using 2.0.0-RC1), I'm guesstimating it's because I have no constructors set, but this shouldn't be needed for an interface, right?v79
05/23/2024, 8:52 PMclass Request<I>(val body: I)
can I get the KType
of I
when the Request
is constructed? Nothing is reified and I definitely cannot call typeOf<I>
.Blake Anderson
08/07/2024, 5:26 AMKFunction
reference to one of the overloads? I found I can use val ref: (String) -> Unit
, for instance, as a way to disambiguate but the resulting type is not KFunction
. It seems like I can cast this without everything crashing, but it's messy to use and not sure how stable that is.Cies
08/21/2024, 7:21 PM@RequiresAnyUserPermissionOf(...)
that takes one or more permission enum instances. We check on each incoming request that that user user is allowed to the action by using reflection to get the annotation of the method and the class and all superclasses (up to some point). I consider caching all this by making some maps like Map<KFunction<Result>, List<Permission>>
and Map<KClass<Controller>, List<Permission>>
so it is all cached and we do not have to (recursively) reflect all over the place to now what permissions are on a certain controller class or controller action method.
I have no clue what a KClass or KFunction actually is! Would this be a good idea? Or should I make these maps based on string representations (and the convert the KFunction or KClass to a string when doing a lookup)? Or doing a bunch of these reflections class to find the annotations soooooo fast that I should not bother at all... Just curious what you have to say on this, and as to how a KFunction or KClass actually is represented in memory.Moe
09/13/2024, 5:54 PMimport kotlin.reflect.full.findAnnotation
import kotlin.reflect.full.primaryConstructor
but now all I'm getting is Unresolved reference: full
although
import kotlin.reflect.KClass
seems to work perfectly fine.
not sure what im missing to be honest, but any assistance would be highly appreciated
This is happening in my JVM module, and it works fine in my androidMain. I have the dependency set to both.
P.S Koltin 2.0.20 Reflect 2.0.20Cies
09/27/2024, 11:55 AM"some.package.ControllerName.actionMethod"
we now use ControllerName::actionMethod
: type safe, refactor friendly, less prone to bugs, and just plain stupid that this is still (2024!) not possible in Java. Thanks to whomever got this right in Kotlin, I enjoy my working life on the JVM a lot better since. 💚💛❤️Nathan Castlehow
11/04/2024, 1:37 AMOuterClass::valueClass
but not when using the KProperty returned form
OuterClass::class.declaredMemberProperties
Minimum repro in thread🧵groostav
11/05/2024, 6:04 AMval x = fun(arg: String) { println(arg) }
val functionRef: KFunction<*> = x::invoke //valid, i can create a reflective handle to invoke.
x::class.members // 6 entries, 2 each of equals, hashcode, tostring. invoke is missing
is this expected behaviour?groostav
11/05/2024, 6:06 AM::invoke
off a KClass
instanceJason
11/08/2024, 8:16 PMAndrey V
11/17/2024, 12:35 AMKClass<*>.declaredMemberProperties
. In the following code example:
data class A<T001>(
val a001:Int?=null,
val a002:Double?=null,
val a003:Int?=null,
val a004:Double?=null,
val a005:Int?=null,
var a007:Double?=null,
val a008:Int?=null,
) {
var a006: T001? = null
val a009 = ""
fun <T002> x() {}
}
A::class.declaredMemberProperties
provides a list of properties in the order listOf(::a001, ::a002, ::a003, ::a004, ::a005, ::a006, ::a007, ::a008, ::a009)
, whereas at the java level, via A::class.java.declaredMethods.filter { it.name.startsWith("get") }
, we get the expected order of properties declared in the primary constructor then properties declared in the body. Why does that happen?Andrey V
11/17/2024, 12:39 AMGergely Kőrössy
11/23/2024, 4:24 AMKClass
or Class
from a KmType
? For example, I have a KmType
with the classifier being KmClassifier.Class
which gives the name kotlin/collections/List
. I have tried Class.forName(...)
with it by replacing the /
with .
, but it doesn't work because the JVM type is actually java.util.List
, so it throws a ClassNotFoundException
for kotlin.collections.List
. This is also true for things like kotlin/Float
. Anyone knows a solution for this problem?marcinmoskala
12/13/2024, 12:51 PMtypeOf<List<Dog>>
is a subtype of typeOf<Iterable<Animal>>
Eric
12/18/2024, 2:40 PMMutableSet
have orphanRemoval = true
on the @OneToMany
annotation, but I can't figure out a good way to detect that using reflection. This works, but I don't like using toString
since that might change. Is there another way that I'm missing that I could use to find all properties that are not an immutable Set?
@Test
fun test() {
val valid = LotEntity::class.declaredMemberProperties
.asSequence()
.filter { it.returnType.isSubtypeOf(Collection::class.starProjectedType) }
.filterNot { it.returnType.toString().startsWith("kotlin.collections.Set") }
.mapNotNull { it.javaField?.getAnnotation(OneToMany::class.java) }
.all { oneToMany -> oneToMany.orphanRemoval }
println(valid)
}
Josh Feinberg
01/10/2025, 3:03 AMAndrey V
01/13/2025, 9:00 AMcallBy
In which cases, for @Serializable data class C
and applicable primary constructor params ...
, can the following expression
((::C).call(...)::copy).callBy(emptyMap())
fail with
KotlinReflectionInternalError(
"Inconsistent number of parameters in the descriptor and Java reflection object: $arity != $expectedArgsSize\n" +
"Calling: $descriptor\n" +
"Parameter types: ${this.parameterTypes})\n" +
"Default: $isDefault
with expectedArgsSize
being the number of primary constructor declared properties + 1 and arity being the number of primary constructor declared properties + 2?
It seems the -1 is due to the reflection logic determining that it's a bound reference to a static method, which seems nonsensical
Reducing the case to ~100 lines made the issue vanish so I'm looking for things to pay attention to for debuggingDamianReeves
02/06/2025, 12:10 AMrad
03/03/2025, 6:37 PMKProperty<*>
in a delegate like such:
operator fun <T : GameDataEntry> getValue(
thisRef: Any?,
property: KProperty<*>
): T {
@Suppress("UNCHECKED_CAST")
return requireNotNull(getData(property.returnType.classifier as KClass<T>))
}
Using Kotlin 2.1.10, is this a bug or am I just doing something wrong? The exception happens even when just attempting to get the returnType