I want to use Pair<Int, Int>
as return type where one of the Int is annotated with @StringRes
.
Pair<@param:StringRes Int, Int>
给出了弃用警告.
I want to use Pair<Int, Int>
as return type where one of the Int is annotated with @StringRes
.
Pair<@param:StringRes Int, Int>
给出了弃用警告.
你不能.问题是Android的@StringRes
不适用于目标TYPE_USE
(或者在Kotlin是TYPE
).
It would work if it was defined like this (java):
@Retention(SOURCE)
@Target({METHOD, PARAMETER, FIELD, TYPE_USE})
public @interface StringRes {
}
Now it would work:
fun fooIt(p: Pair<@StringRes Int, Foo>) {}
还有一个悬而未决的问题:https://issuetracker.google.com/issues/109714923
但是,尽管出现了弃用警告,您的解决方案仍有可能真正起作用.我还没有测试过.