这个陈述有什么问题?
List<Integer> phDigits = new List<Integer>();
Error: Cannot instantiate the type List <Integer>
Run Code Online (Sandbox Code Playgroud)
是的,我知道我可以使用new ArrayList<Integer>()- 我问为什么第一个声明不起作用.
编辑:这是我有一个有效的问题..对于SO标准来说太简单了?
List是一个接口,这意味着其他类可以实现它.如果一个类实现List,那么你可以编写
List<Integer> something = new ClassThatImplementsList<Integer>();
Run Code Online (Sandbox Code Playgroud)
List可以用作类型,因为实现的任何东西List都是a List,但是你不能在Java中说"make a List",因为它不知道如何.所有这些List都提供了必须实现的方法,但它不包含实现.