痛点
我们经常会定义一些常量,比如
public interface ItemType {
public static final int TYPE_TEXT = 0;
public static final int TYPE_IMG = 1;
public static final int TYPE_VIDEO = 2;
public static final int TYPE_AUDIO = 3;
public static final int TYPE_LINK = 4;
}
当我们打印查看是哪种类型的时候,如果单纯是打印int值,并不能足够解释业务信息,所以,为了更好的输出信息,我们通常会这样做
private fun inspectItemTypeUgly(itemType: Int) {
val type = when(itemType) {
ItemType.TYPE_TEXT -> "text"
ItemType.TYPE_AUDIO -> "audio"
ItemType.TYPE_IMG -> "image"
ItemType.TYPE_LINK -> "link"
ItemType.TYPE_VIDEO -> "video"
else -> null
}
println("inspect item type =${inspectItemTypeUgly(itemType)};originalValue=$itemTy