I'm trying to make an ArrayList that contains an object of another class, a name, and turn. something similar to the python's dictionary.
self.user1 = {"user":user1,"name":empty,"turn":empty}
so I made a class that has the 3 values.
class User{
public userInterface user1;
String name;
String turn;
public User(UserInterface user1,String name,String turn) {
this.user1=user1;
this.name=name;
this.turn=turn;
}}
and I'm trying to call it in the constructor of main class as following:
public class MainClassConstructon{
ArrayList<User> user1;
ArrayList<User> user2;
MainClassConstructon(UserInterface user1 ,UserInterface user2){
this.user1 = new ArrayList<>(new User(user1,empty, empty));
this.user2 = new ArrayList<>(new User(user2,empty, empty));
but it raises an error saying that: cannot infer type arguments for ArrayList<>.
new ArrayList<>(Arrays.asList(new User(user1,empty, empty)));.emptycome frominMainClassConstructon? @lexicore: this would create aArrayList<List<User>>...Collections.singletonList. If they are going to grow, then create them empty first, then add the element.User.ArrayListhas a(Collection<? extends E> c)constructor.