【问题标题】:Create a class with objects of type List [duplicate]使用 List 类型的对象创建一个类 [重复]
【发布时间】:2015-02-27 19:31:15
【问题描述】:

我是 JAVA 的新手,如何使用 List 类型的对象创建一个类。

public class Information {

    public String Name;
    public double Age;
    **public List<String> vechicleType=** new ArrayList<String>();**

    }

我收到如下错误:

The type List is not generic; it cannot be parameterized with arguments <String>

是否可以在 hashmap 中使用它,例如:

我想使用 HashMap

HashMap<String, Information> hm = new HashMap<String,Information>();

谢谢!

【问题讨论】:

    标签: java list hashmap


    【解决方案1】:

    您的班级中一定有错误的导入。

    不要导入java.awt.List,而是导入java.util.List

    【讨论】:

    • 哇!!我没有看到它的到来!非常感谢!
    • @user1799214 这在 dup Q/A 中进行了解释,并提供了更多详细信息。
    猜你喜欢
    • 2012-03-13
    • 2012-12-17
    • 1970-01-01
    • 2023-01-20
    • 1970-01-01
    • 2011-10-22
    • 1970-01-01
    • 1970-01-01
    • 2011-09-29
    相关资源
    最近更新 更多