Why is my IDEA reporting this error - "Cannot resolve symbol 'synchronizedList'"

637 views Asked by At
public static List<Socket>  socketList = new Collections.synchronizedList(new ArrayList<>());

In the code, Collections.synchronizedList, prompt me Cannot resolve symbol synchronizedList, I don't know what it is. I didn't find this method for Collections in the JDK documentation either (just because I probably couldn't find it, doesn't mean he didn't).

Maybe it's a problem with my IDEA setup, but I can't find it.

2

There are 2 answers

0
AudioBubble On

because synchronizedList is not a class from Collections - it is a method.

Remove the new keyword from that statement:

public static List<Socket>  socketList = Collections.synchronizedList(new ArrayList<>());

The new keyword is used to create a new instance of a class and requires a class, but the compiler is not able to find that class => symbol not found

0
João Zarate On

You need to remove the new statement from Collections.

public static List socketList = Collections.synchronizedList(new ArrayList<>());