在 kotlin 中有必要用常量注解吗?如果需要用下面的常量类用 kotlin 应该怎么写呢,直接转换 kotlin 会报错。
import androidx.annotation.StringDef;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author Luke
* @version 1.0.0
* @time 2020/7/13 2:14 PM
* @description 常量池
*/
public class Constant {
@IntDef({
AlertCode.SYSTEM,
})
@Documented
@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.PARAMETER, ElementType.FIELD, ElementType.METHOD})
public @interface AlertCode {
int SYSTEM = 0;
}
}
1
gz911122 2020-07-15 10:11:00 +08:00
这是干啥用的啊?
|
4
lianyue13 2020-07-15 10:26:11 +08:00
```kotlin
class Constant { @IntDef(AlertCode.SYSTEM) @Documented @Retention(AnnotationRetention.SOURCE) @Target(AnnotationTarget.LOCAL_VARIABLE, AnnotationTarget.FIELD, AnnotationTarget.FUNCTION) annotation class AlertCode { companion object { const val SYSTEM = 0 } } } ``` |
6
loshine1992 2020-07-15 10:32:15 +08:00
ART 之后直接用枚举就可以了
|