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

已导入相关类库,List和ArrayList仍出现波浪线问题求助

Java中List/ArrayList出现波浪线的解决方法

1. 类名与包名冲突问题

你的类名list和所在包名list完全重名,这会导致编译器无法正确区分自定义类和java.util下的List/ArrayList,从而出现波浪线提示。

  • 修复方式:修改类名,遵循Java类名首字母大写的规范,比如改为ListDemo,修改后的代码:
package list;

import java.util.ArrayList;
import java.util.List;

public class ListDemo {
    
    public static void main(String[] args)
    {
       List l = new ArrayList();
    }
}

2. 原始类型警告

代码中使用了无泛型的原始类型List l = new ArrayList();,IDE会因为类型未检查而给出警告波浪线。

  • 修复方式:添加泛型参数,示例如下:
// 若存储字符串类型
List<String> l = new ArrayList<>();
// 若存储整数类型
List<Integer> l = new ArrayList<>();

3. IDE缓存异常

如果上述修改后波浪线仍未消失,大概率是IDE缓存问题:

  • 修复方式:
    • 清理IDE缓存(比如IntelliJ IDEA选择File -> Invalidate Caches...,勾选选项后重启)
    • 重新编译整个项目(Build -> Rebuild Project)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 09:43:11