I am using the java enum io.confluent.kafka.schemaregistry.avro.AvroCompatibilityLevel in Kotlin code
public enum AvroCompatibilityLevel {
NONE("NONE", AvroCompatibilityChecker.NO_OP_CHECKER),
// ...
public final String name;
public final AvroCompatibilityChecker compatibilityChecker;
// ...
In Kotlin I'd like to make use of
AvroCompatibilityLevel.NONE.name
but this leads to an
Overload resolution ambiguity. All these functions match:
public final val name: String? // coming from the field name
public final val name: String // coming from enum
Can anyone point out how to overcome this issue?
You can write an extension property to extract the value of the member field "name" like this:
import kotlin.reflect.full.memberProperties
private val innerNameCache = mutableMapOf<AvroCompatibilityLevel, String>()
val AvroCompatibilityLevel.innerName: String
get() = innerNameCache.getOrPut(this) {
AvroCompatibilityLevel::class.memberProperties.filter { it.name == "name" }[0].get(this) as String
}
fun main() {
println(AvroCompatibilityLevel.NONE.innerName)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With