(it's building a `Map<KClass<*>, KSeriali...
# serialization
b
(it's building a
Map<KClass<*>, KSerializer<*>>
, which I believe does in fact require kotlin-reflect to materialize the entire KClass.
k
afaik that should work as part of stdlib?
b
I'd have thought so, too, but for the error. In my code, simple uses of KClass seem to compile down to references to java classes, but any interaction with a KClass instance (like taking its hashcode, for example) seems to result in bytecode referencing kotlin-reflect.
😕 1
Using the "view bytecode" feature in intellij,
Int::class.hashCode()
becomes
Copy code
GETSTATIC java/lang/Integer.TYPE : Ljava/lang/Class;
INVOKESTATIC kotlin/jvm/internal/Reflection.getOrCreateKotlinClass (Ljava/lang/Class;)Lkotlin/reflect/KClass;
INVOKEINTERFACE kotlin/reflect/KClass.hashCode ()I (itf)
POP
which appears likely to involve
kotlin-reflect
this of course is what happens when building a map, which will take the hash code of each of its keys
I may be missing something fundamental, but this kind of usage of KClass seems reasonably likely to require kotlin-reflect
😞 1
m
kotlin/jvm/internal/Reflection.getOrCreateKotlinClass
is a lightweight abstraction around Kotlin reflection. It uses either
kotlin-reflect
if present or some limited
kotlin-stdlib
magic if not. The latter includes creating
KClass
instances with limited functionality. Putting them in a
Map
is fine. Also, the package
kotlin.reflect
is
kotlin-stdlib
and only
kotlin.reflect.full
is
kotlin-reflect
.
b
That's what I was thinking might be the case. In that case, I wonder why this error happens when
kotlin-reflect
isn't on the classpath?