java - IntelliJ - 无法解析符号 'Arrays'

标签 java intellij-idea collections

  1. 我的代码

My Code

  • SDK 级别
  • SDK & Level Settings

  • SDK
  • SDK

    我正在使用

    1. Windows 7 32 位操作系统
    2. Java 版本“1.8.0_221”
    3. IntelliJ Idea 11.0.2

    我正在用 Java 编写一个基本程序。但我收到编译错误:

    Cannot resolve the symbol 'Arrays'

    我的代码是这样的:

    import java.util.Arrays;
    import java.util.Collections;
    
    import java.util.List;
    
    public class EmployeesData {
    
        public static List<Employee> getEmployees() {
            return Arrays.asList(
                    new Employee(201, "Kumar", "MS", 20000),
                    new Employee(202, "Kiran", "Wells", 30000),
                    new Employee(201, "Kumar", "Wells", 40000), 
                    new Employee(203, "Vishal", "MS", 25000),
                    new Employee(203, "Srikanth", "MS", 45000),
                    new Employee(204, "Vimal", "Wells", 50000));
        }
    
        public static List<Employee> getEmployees2() {
            String a = null;
            return Collections.singletonList(
                    new Employee(201, "Kumar", "MS", 20000),
                    new Employee(202, "Kiran", "Wells", 30000),
                    new Employee(201, "Kumar", "Wells", 40000),
                    new Employee(203, "Vishal", "MS", 25000),
                    new Employee(203, "Srikanth", "MS", 45000),
                    new Employee(204, "Vimal", "Wells", 50000));
        }
    }
    

    对于 Collections 类,我也遇到了同样的错误。

    我也在 E​​clipse 中尝试过,我在 Eclipse 中也面临同样的问题。我也尝试指定库。甚至没有解决。可能我必须在设置中做额外的事情。

    最佳答案

    以下作品...

    public static List<Employee> getEmployees() {
    
            Employee[] e = {new Employee(201, "Kumar", "MS", 20000),
                    new Employee(202, "Kiran", "Wells", 30000),
                    new Employee(201, "Kumar", "Wells", 40000), 
                    new Employee(203, "Vishal", "MS", 25000),
                    new Employee(203, "Srikanth", "MS", 45000),
                    new Employee(204, "Vimal", "Wells", 50000)};
    
            return Arrays.asList(e);
        }
    

    ...我怀疑编译器不喜欢 new 关键字。

    关于java - IntelliJ - 无法解析符号 'Arrays',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57769907/

    相关文章:

    java - Karate :使用 JUnit5 的运行者类(class)

    android-studio - 如何在kotlin coroutine中显示 “@coroutine#2” ,“@coroutine#3” ,“@coroutine#1”?

    sorting - JAXB 强制对集合进行排序

    java - 树集重复项

    c# - 我有什么选择可以使这段代码线程安全?

    java - 我可以在 Windows 7 操作系统上安装 dbpedia Spotlight

    java - Zxing 库实现 : And the below part on getting back the result after the scanning Activity gives an error

    java - 如何在 Java 中像 Entity Framework C# 一样在 hibernate 状态下创建数据库上下文文件

    intellij-idea - Intellij IDEA 15 中的持久化工具窗口在哪里?

    java - 如何防止 Intellij 删除 getter 和 setter 的换行符