import java.util.HashMap;
public class HashMap {
public static void main(String[] args)
{
HashMap<String, String> map = new HashMap<>(); //新建一张哈希表
}
}
代码会出现错误提示:The type HashMap is not generic; it cannot be parameterized with arguments <String, String>
是因为自己新建的类名与导入包的名字相同引起的错误,应该在取类名时应该避免这种情况。修改后如下所示:
import java.util.HashMap;
public class UsingHash {
public static void main(String[] args)
{
HashMap<String, String> map = new HashMap<>();
}
}