I am making a delegated property... I am really cl...
# announcements
a
I am making a delegated property... I am really close to finishing it, but the return type (
Any
) is such that Kotlin can not recognize it as a delegate. Any way I can fix this?
Copy code
inline fun <reified T : Any> ConfigurationSection.tester(
    basePath: String,
    default: T,
    crossinline accept: (T) -> Boolean = { true }
): Any {
    return object {
        operator fun getValue(thisRef: T, property: KProperty<*>): T {
            val camelCase = property.name.hyphenate()
            val path = "$basePath.$camelCase"
            val res = this@tester[path]

            return when (res) {
                null, !is T, !accept(res) -> {
                    this@tester[path] = default
                    default
                }
                else -> res
            }
        }
    }
}