https://kotlinlang.org logo
#announcements
Title
# announcements
k

kirillrakhman

01/13/2017, 4:01 PM
@snowe please try something like this:
Copy code
class Builder {
    private var currentInterestRate: BigDecimal? = null

    fun getFunctionFromObjectName(funcName: String, ob: Any): Builder {
        val prop = Builder::class.declaredMemberProperties.find { e -> e.name == funcName } as KMutableProperty<*>
        prop.setter.isAccessible = true
        prop.setter.call(this, ob)
        return this
    }
}

fun main(args: Array<String>) {
    Builder().getFunctionFromObjectName("currentInterestRate", BigDecimal.ONE)
}