Reputation: 221
I created a new class with for a new List with 2 entries:
public class NodeList<T, I> {
public final T type;
public final I id;
public NodeList (T type, I id){
this.type = type;
this.id = id;
}
public T getT() { return type; }
public I getI() { return id; }
}
Now I want to create this List inside another class (Controller of my javafx BorderPane)
List<NodeList> nodeList = new ArrayList<NodeList>();
And I want to add two Strings in this List.
public void addNodeList(){
String a = "a";
String b = "b";
nodeList.add(a, b);
}
What am I doing wrong?
Upvotes: 0
Views: 43
Reputation: 28056
You need to create a new object of type NodeList
. A List
does not have an add method that takes two strings directly. To fix it, do this:
public void addNodeList(){
String a = "a";
String b = "b";
nodeList.add(new NodeList<String, String>(a, b));
}
Upvotes: 1
Reputation: 312086
There are no "implicit constructors" in Java. You have to explicitly instantiate a new NodeList
to hold the two Strings:
public void addNodeList(){
String a = "a";
String b = "b";
nodeList.add(new NodeList<>(a, b));
// Here -----^
}
Upvotes: 2