https://kotlinlang.org logo
#dagger
Title
# dagger
d

dave08

09/19/2021, 6:39 AM
Is there a way to inject a
value class
with Dagger2? It seems like it's not working... (don't think it makes a difference, but I'm using Anvil with it...)
e

ephemient

09/19/2021, 7:13 AM
as long as Dagger is using (K)APT and generating Java, probably not
d

dave08

09/19/2021, 7:16 AM
Yeah, I guess that makes sense... but under the hood doesn't a value class compile to a Java value class, or is Kapt not smart enough?
e

ephemient

09/20/2021, 1:25 AM
under the hood, a
@JvmInline value class Value(val value: T)
compiles to a combination of things: • properties, variables, methods, constructors, etc. declared as type
Value
compile to directly use
T
, but with mangled names to avoid collisions with Java overloads on
T
• a wrapper class
Value
for use in contexts where the above can't work (e.g.
List<Value>
), with boxing/unboxing-like operations around its use for now, all Kotlin/JVM value classes must be `@JvmInline`; Java's Project Valhalla is not ready and thus there are no JVM primitive classes yet. there isn't a lot that KAPT can sensibly do with value classes - the mangled names aren't valid Java identifiers
🙏 2
8 Views