Quantcast
Channel: How do I use multiple lines in Kotlins when switch? - Stack Overflow
Viewing all articles
Browse latest Browse all 3

How do I use multiple lines in Kotlins when switch?

$
0
0

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?


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>