Home > Software engineering >  .copy function showing red and did not accept any value
.copy function showing red and did not accept any value

Time:07-02

private fun mPerformDeletion() {
    when {
        state.mNumber2.isNotBlank() -> 
            state = state.copy(mNumber2 = state.mNumber2.dropLast(1))
    }
}

CodePudding user response:

Your when should have a condition inside a bracket () but you are using {}.
Also when is not required for single conditional statements, you can use iflike:

private fun mPerformDeletion() {
    // assuming state is a `var` & is a `data` class
    if (state.mNumber2.isNotBlank()) { 
        state = state.copy(mNumber2 = state.mNumber2.dropLast(1))
    }
}

CodePudding user response:

Sorry about that i forgot to mention the "var mNumber2" class as a data class. when i write it " data class " Error is solved.

  • Related