为什么在创建我的arraylist时会遇到错误?

发布于 2025-02-13 07:12:57 字数 1773 浏览 3 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

筑梦 2025-02-20 07:12:57

您可以调用类arrayList,但这是一个非常糟糕的主意。最好重命名。其次,您有两个具有相同名称的变量,这是禁止的。正确的代码看起来像:

import java.util.*;

public class ArrayListTest {   
    public static void main(String[] args) {
        List<Integer> list1 = new ArrayList<>();
        ArrayList<Integer> list2 = new ArrayList<>();
    }   
}

You can call your class ArrayList but it is a very bad idea. Better to rename it. Second, you have two variables with the same name, which is forbidden. A correct code looks like:

import java.util.*;

public class ArrayListTest {   
    public static void main(String[] args) {
        List<Integer> list1 = new ArrayList<>();
        ArrayList<Integer> list2 = new ArrayList<>();
    }   
}
温馨耳语 2025-02-20 07:12:57

将课堂名称重命名为其他。

arrayList是带有java.util软件包的类
由于您导入了java.util。*,因此程序无法从util软件包中选择此类或类。

import java.util.*;

public class MyArrayList {

    public static void main(String[] args) {
        List<Integer> List = new ArrayList<>();
        ArrayList<Integer> List = new ArrayList<>();
    }
    
}

Rename class name to something else.

ArrayList is a class that came with java.util package
Since you imported java.util.* , the program can't select this class or the class from util package.

import java.util.*;

public class MyArrayList {

    public static void main(String[] args) {
        List<Integer> List = new ArrayList<>();
        ArrayList<Integer> List = new ArrayList<>();
    }
    
}
梦冥 2025-02-20 07:12:57

您使用的是相同的名称,因此在计算机存储中,如果编译器不干预,它们将相互覆盖(理论上)。只需在您的两个变量中添加一个指示器,例如“ 1”和“ 2”!

You are using the same name, so in the computers storage they would overwrite each other (in theory), if the compiler wouldn't intervene. Just add an indicator to your two variables, like '1' and '2'!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文