<https://stackoverflow.com/questions/52812997/when...
# stackoverflow
u
'when' expression must be exhaustive error when using adapters I would like to do something like this: class MyPagerAdapter : PagerAdapter() { override fun getItem(position: Int) = when(position) { 0 -> Fragment0() 1 -> Fragment1() } override fun getCount() = 2 } I am sure that the adapter contains only 2 items, so getCount() simply returns 2. But it shows an error message said that 'when' expression must be exhaustive, add necessary 'else' branch. I understand that I can add an else to solve it, but it's really ugly to...