The plugin which lets you easily inline your value classes with a single annotation:
import io.github.jvmusin.naked.Naked
@JvmInline
value class Wrapper(val data: String)
@JvmInline
@Naked
value class InlinedWrapper(val data: String)
fun main() {
println("Hello, ${Wrapper("World")}!") // Prints "Hello, Wrapper(data=World)!"
println("Hello, ${InlinedWrapper("World")}!") // Prints "Hello, World!"
}
The reason you may want to inline value classes entirely is to avoid unnecessary boxing when value classes are used as generic or nullable types.
Applying @Naked
annotation to the value class causes all the real objects of this type to be replaced with a
wrapped value – with a string in the example above.
-
Register the plugin
io.github.jvmusin.naked
in theplugins
section of your project'sbuild.gradle.kts
file:plugins { ... your other plugins id("io.github.jvmusin.naked") version "0.0.1" }
-
Annotate your value classes with
@io.github.jvmusin.naked.Naked
-
That's it! All usages of the annotated class will be replaced with usages of the wrapped value!
You can disable the plugin using naked
extension in build.gradle.kts
file:
naked {
enabled = false
}