我的Java项目有一个具有给定值的ItemType接口,该接口由某些类实现。如何在Kotlin上实现此接口?
public interface ItemType {
int TYPE_OPTION = 2;
int TYPE_GRID = 3;
int TYPE_CAROUSEL = 4;
int TYPE_MUSIC = 5;
int TYPE_GUESS = 6;
int getItemType();
}
答案 0 :(得分:3)
您可以使用companion object
:
interface ItemType {
val itemType: Int
companion object {
const val TYPE_OPTION = 2
const val TYPE_GRID = 3
const val TYPE_CAROUSEL = 4
const val TYPE_MUSIC = 5
const val TYPE_GUESS = 6
}
}