https://kotlinlang.org logo
s

snowe

01/13/2017, 5:10 AM
is there any way to get a private property by name? I'm getting this error with this code
kotlin.reflect.IllegalCallableAccessException: Class kotlin.reflect.jvm.internal.FunctionCaller$FieldGetter can not access a member of class com.promontech.loanapp.projection.loan.viewmodel.loandetails.LoanDetailsView$Loan$Builder with modifiers "private"
Copy code
class Builder {
    private var currentInterestRate: BigDecimal? = null

    fun currentInterestRate(currentInterestRate : BigDecimal): Builder {
        val built = getFunctionFromFile("currentInterestRate", currentInterestRate)
        println(currentInterestRate)
        return built
    }
    
    // Goal is for this to take in object, pull out object name, find property with same name
    // and set that property to the value of the object passed in
    fun getFunctionFromObjectName(funcName: String, ob: Any): Builder { //KFunction<*>? {
        Builder::class.members.find { e -> e.name == funcName }?.call(ob)
        return this
    }
  }