当我将新的属性文件添加到资源内的项目并将其命名为“lang1”时,BUNDLE_NAME 会被正确识别。
但是,如果我添加包含 lang2_de 和 lang2_en 的 ResourceBundle 并尝试使用其基本名称作为 BUNDLE_NAME,则会显示以下错误“资源包引用‘lang2’无效。
所以我基本上有 3 个文件。
- lang1_de.properties
- lang2_de.properties
- lang2_en.properties
lang2 被捆绑到一个带有“'base name' = lang2”的资源包中
这是与 kotlin 一起使用的:
private const val BUNDLE_NAME = "lang1"
fun foo(@PropertyKey(resourceBundle = BUNDLE_NAME) key: String): String {
return key
}
这不是:
private const val BUNDLE_NAME = "lang2"
fun foo(@PropertyKey(resourceBundle = BUNDLE_NAME) key: String): String {
return key
}
但是如果我用 java 做同样的事情,它就可以工作......
private static final String BUNDLE_NAME = "lang2";
public static void foo(@PropertyKey(resourceBundle = BUNDLE_NAME) String key) {
return key;
}
我这样做是为了获取有关我的代码中使用的属性的信息。
这两个示例的属性文件中的属性均已正确标记。
但是对于 lang2,代码中使用的字符串均显示检查错误“字符串文字 'testprop' 似乎不是有效的属性键...”
我还在 JetBrains/java-annotations 中为此创建了一个问题:
https://github.com/JetBrains/java-annotations/issues/13
最佳答案
感谢您的报告,该bug已提交至https://youtrack.jetbrains.com/issue/KT-31359 ,请follow it for updates .
关于java - @PropertyKey 注解不适用于 Kotlin,但适用于 Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55915462/