You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

带包名的类使用@Valid注解报错:Annotation not applicable to this kind of reference

问题:@Valid注解在List泛型中使用全限定类名时触发报错

可正常运行的代码

public class Foo {

    private List<@Valid String> bar = Collections.emptyList();
}

运行异常的代码

public class Foo {

    private List<@Valid java.lang.String> bar = Collections.emptyList();
}

IDE报错信息

注解不适用于此类引用

附带现象

同时List的导入会被标记为未使用状态:
IDE中显示List导入未使用的截图


内容的提问来源于stack exchange,提问作者gstackoverflow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 00:50:55