Reputation: 21019
I am using generics in a certain data structure. I have to store int x
, int y
, and Value value
, where value
is the generic type.
I am trying to group all those in one object called NodeData
and then in another class, create an ArrayList of NodeData
's, (so each element in the array list will include hold an x, y and value.
My NodeData
is as follows:
public class NodeData<Value> {
private int x;
private int y;
private Value value;
In another class, the array list instantiated as follows: ArrayList<NodeData> items = new ArrayList<NodeData>();
.
I am getting an error for the array list which says: NodeData is a raw type. References to NodeData<Value> should be parametrized.
Why is that? NodeData
is already parametrized as NodeData<Value>
.
Thanks
Upvotes: 1
Views: 124
Reputation: 108957
In the other class, You'll have to specify the type you intend to use in place of the generic type Value
eg.
ArrayList<NodeData<String>> items = new ArrayList<NodeData<String>>();.
Upvotes: 2
Reputation: 308763
Not in your array declaration. Try it like this:
List<NodeData<Foo>> list = new ArrayList<NodeData<Foo>>();
where Foo
is the Value
type you want for that instance.
Upvotes: 4