Cannot instantiate the type Map

今天在使用Map中犯了个低级错误,记录一下:

打算使用map为一个视频List观看记录的统计标识,key为vid,value默认为false,当该key已经统计,标识value为true,初始实例化Map代码如下:

Map<String, Boolean> vListMap= new Map<String, Boolean>();

报错:Cannot instantiate the type Map

查看Map的定义,public abstract interface java.util.Map

原来Map是一个抽象接口,不能直接实例化,我们需要使用它的实现类,正确代码如下:

Map<String, Boolean> vListMap= new HashMap<String, Boolean>();

猜你喜欢

转载自www.cnblogs.com/mobingfeng/p/10149568.html