Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Synchronized arrayList- incompatible types

I'd like to create synchronized ArrayList in JAVA. I've used this code:

static ArrayList<User> listOfUsers = Collections.synchronizedList(new ArrayList<User>());

But NetBeans yells:

incompatible types:

required: ArrayList found: List

Any help possible?

like image 251
Vardens Archangel Avatar asked Jun 18 '26 15:06

Vardens Archangel


1 Answers

Collections.synchronizedList() returns a List, not an ArrayList. Declare the user list as such:

static List<User> listOfUsers = Collections.synchronizedList(new ArrayList<User>());
like image 68
kiheru Avatar answered Jun 20 '26 04:06

kiheru



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!