在 Kotlin 中抑制 DeprecationLevel.ERROR

Jes*_*son 1 kotlin

我在我的 API 中使用DeprecationLevel.ERROR

@Deprecated(
    message = "moved to def()",
    replaceWith = ReplaceWith(expression = "def()"),
    level = DeprecationLevel.ERROR)
fun abc() = def()
Run Code Online (Sandbox Code Playgroud)

我想要一个测试来确保调用者看到这个替换。例如,如果我不小心删除了该abc()方法,我的测试应该无法编译。

但我找不到编译这个的方法:

@Test
@Suppress("something")
fun deprecatedAbc() {
  abc()
}
Run Code Online (Sandbox Code Playgroud)

例如,@Suppress("DEPRECATION")不起作用。有什么可以做的吗?

Ban*_*non 5

根据DefaultErrorMessages,您可以使用@Suppress("DEPRECATION_ERROR").