Reputation: 11
So I am trying to create a 2D array of nodes which are basically 2D plot coordinates. The first column so to speak (ie. [0][0], [1,0] ...) will be the head element wheras all points in the same row following it are successors which link to the first point. From this I am implementing some simple search algorithms. The class I have created (MyPair) simply takes two arguments being aVal, bVal which are both ints. However I don't know how to put these custom objects a 2D array without compilation errors. A snippet of the code follows.
public class GraphNodes {
public MyPair[][] graphNodes;
public GraphNodes(){
this.graphNodes = new MyPair[][]
{{(0,0), (1,0), (0,1)},
{(0,1), (0,0), (1,1), (0,2)},
{(0,2), (0,3), (0,1)},
{(0,3), (0,2), (0,4)},
{(0,4), (0,3), (0,5)},
{(0,5), (0,6), (1,5), (0,4)},
{(0,6), (1,6), (0,5)},
{(1,0), (0,0), (1,1), (2,0)},
{(1,1), (1,2), (2,1), (1,0), (0,1)},
I thought doing it this way would work but I am getting an error saying The left-hand side of an assignment must be a variable
in eclipse. Any ideas?
Upvotes: 1
Views: 168
Reputation: 393896
(0,0)
cannot be converted by the compiler to your MyPair
class automatically.
You have to invoke a constructor such as new MyPair(0,0)
(assuming you have such a constructor).
If you have such a constructor, you can replace any (x,y)
in your code with new MyPair(x,y)
.
Upvotes: 1