我的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();
}
您可以使用伴生对象
:
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
}
}