我开发Android应用程序,并经常使用注释作为编译时参数判断,主要是Android的support annotations.
java代码中的示例:
public class Test
{
@IntDef({Speed.SLOW,Speed.NORMAL,Speed.FAST})
public @interface Speed
{
public static final int SLOW = 0;
public static final int NORMAL = 1;
public static final int FAST = 2;
}
@Speed
private int speed;
public void setSpeed(@Speed int speed)
{
this.speed = speed;
}
}
我不想使用enum,因为它们在安卓系统中存在性能问题.kotlin的自动转换器只会生成无效代码.如何在kotlin中使用@IntDef
注释?