Builders for implementations need to be unified. A Function object is being created every time and Java consumers always need to return Unit. Additionally, static implementations are not being re-used when builder configurations are the same; new instances are always being created.
Migrate all implementations to a EncoderName.Builder class, with associated lambda functions for Kotlin consumers on the encoder implementation's companion object.
e.g.
public class EncoderName {
public class Builder {
public constructor(): this(other = null)
public constructor(other: Config?) {
// ...
}
// ...
public fun build(): EncoderName = Config.build(this)
}
public companion object {
@JvmStatic
@JvmName("-Builder")
@OptIn(ExperimentalContracts::class)
public inline fun Builder(block: Builder.() -> Unit): EncoderName {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
Builder(other = null, block)
}
@JvmStatic
@JvmName("-Builder")
@OptIn(ExperimentalContracts::class)
public inline fun Builder(other: Config?, block: Builder.() -> Unit): EncoderName {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
return Builder(other).apply(block).build()
}
}
}
Builders for implementations need to be unified. A
Functionobject is being created every time and Java consumers always need to returnUnit. Additionally, static implementations are not being re-used when builder configurations are the same; new instances are always being created.Migrate all implementations to a
EncoderName.Builderclass, with associated lambda functions for Kotlin consumers on the encoder implementation's companion object.e.g.