Cannot instantiate the type List的解决办法

错误代码示例:

private List<Component> children=new List<Component>();

Java中的如上代码将会报出下面这样的的错误,原因是list是接口,而接口不能实例化,故不能直接使用new list直接进行实例化,需要使用任意一个可以实现该接口的类进行实例化,比如:ArrayList

 正确代码示例: 

private List<Component> children=new ArrayList<Component>();

猜你喜欢

转载自blog.csdn.net/syy1292/article/details/90706222