如何强制 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 Compiler Plugin / KSP 实现防护?