【发布时间】:2021-12-18 16:59:21
【问题描述】:
如何强制 Kotlin Annotation 参数的名称显式声明?
// Having an annotation class Foo
annotation class Foo(val bar: String)
// This declaration should work
// we explicitly provided parameter name
@Foo(bar = "42")
class X
// This should fail
// we didn't explicitly provide a name
@Foo("42")
class Y
据我了解,不可能使用现有的 Kotlin 编译器和/或 IDE?我说的对吗?
如果我们正在考虑自定义实现:
- Kotlin 生态系统中有现成的解决方案吗?
- 是否可以使用 Kotlin 编译器插件/KSP 实现防护?
【问题讨论】:
标签: kotlin annotations kotlinc