如何解决用于Kotlin枚举构造函数参数长度验证的androidx.annotation.Size
我想验证枚举构造函数参数的长度,但是androidx.annotation.Size
注释似乎不适用于Kotlin枚举。
如何在Kotlin中使用@Size
批注验证枚举构造函数参数?
例如,这是Java,一切正常:
enum Test2 {
ONE("long string here"),TWO("long string here");
Test2(@Size(min = 0L,max = 4L) String testValue) {
this.testValue = testValue;
}
private final String testValue;
public String getTestValue() {
return testValue;
}
}
还有Kotlin示例:
enum class Test(
@Size(min = 0L,max = 4L) val testValue: String
) {
ONE("long string here"),TWO("long string here")
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。