Kotlin uses when
instead of switch
and it looks something like this:
when(version) {"v1" -> Log.d("TAG", "WOW")"v2" -> Log.d("TAG", WOAAH") else ->"Log.d("TAG", "ELSE")
So far so good. But what if I want to add several lines of code after each conditional? This is my code, and I have tried using and
at the end of each new line:
when(version) {"anhorig" -> Log.d("TAG", "Anhorig") and subHeader.text = getString(R.string.sv_anhorig_ch1)"personal" -> Log.d("TAG", "Personal") else -> Log.d("TAG", "Else")}
I get an error on line
subHeader.text = getString(R.string.sv_anhorig_ch1)
saying Type mismatch. Expected Int, found string and Unit
The code line works fine if separated from the when
code. What am I doing wrong?