我有这个代号:
statisticsSettings = when (ScreenHandler.convertPixelsToDp(width, context).toInt()){
320 -> StatisticsSettings.SMALL_PHONE
480 -> StatisticsSettings.LARGE_PHONE
600 -> StatisticsSettings.SMALL_TABLET
720 -> StatisticsSettings.LARGE_TABLET
else -> throw IllegalArgumentException("Cannot compute dp")
}
我想知道如果我可以让情况下的 when
声明与比较,而不是一个整数。 事情是这样的:
statisticsSettings = when (ScreenHandler.convertPixelsToDp(width, context).toInt()){
ScreenHandler.convertPixelsToDp(width, context).toInt()) < 320 -> StatisticsSettings.SMALL_PHONE
ScreenHandler.convertPixelsToDp(width, context).toInt()) < 480 -> StatisticsSettings.LARGE_PHONE
ScreenHandler.convertPixelsToDp(width, context).toInt()) < 600 -> StatisticsSettings.SMALL_TABLET
ScreenHandler.convertPixelsToDp(width, context).toInt()) < 720 -> StatisticsSettings.LARGE_TABLET
else -> throw IllegalArgumentException("Cannot compute dp")
}
filter
与find
. 这将使更多的意义在这里。