gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 01:00:50 27 4
gpt4 key购买 nike

  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/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com