The err part is Capitalized in the code, it also comes in foreaching. Because of the abstract list, it cannot be initialized, declaration is in a static field. The lists have the same type.
import java.util.*;
public class Test
{
public static final List<String> highPrio = Arrays.asList("*","/");
public static List<String> ops;
public static void main(String[] args)
{
//ERROR HERE, why do it throw nullPointer?
ops.addAll(highPrio);
for(String s : ops)
{
System.out.println(s);
}
}
}
Why not new List() in the initialization?
The reason for not initialization was the inability to use = new List<String>()
. I cannot see a logic not allowing it. It must have something to do with intrinsic factors such as data strucs or something else.
Test.java:7: java.util.List is abstract; cannot be instantiated
public static List<String> ops = new List<String>();
Why list is an interface?
I know that many data strucs such as stack implements list. But I cannot understand why List is an interface and why not Table for example. I see list as a primitive structure with which you can implement other structures. Interface is a thing where you can specify requirements for a structure. Is the primitivenness or extensivenss reason for being an interface?