One of my class project is created a linkedlist2d array clas and i think im on the right track as of now or have an idea of what to do but one of my problem is in this method i am trying to pass two integers. The first integer will be rows and the second int will be columns. let say i am passed (2,3) to this method that means I should have 6 new null nodes. I tried this method right here and it says, "cannot infer arguments". What does that mean exactly and how can I fix this. if this program work there should be 6 nodes: newNodes[0,0], newNodes[0,1], newNodes[0,2] newNodes[1,0], newNodes[1,1], newNodes[1,2]
public Array2D(int rows, int cols){
this.rows=rows;
this.cols=cols;
Array2DNode<E> [][]newNodes = new Array2DNode<>();
for (int countRows=0; countRows< rows; countRows++){
newNodes[countRows][0] = new Array2DNode<>();
for (int countCols=1; countCols < cols; countCols++){
newNodes[countRows][countCols] = new Array2DNode<>();
}
}
Well first off you defined your
Array2DNode<E> [][]newNodes = new Array2DNode<>();
As a Array2DNode Object, Which You havent provided the code to but id assume this shouldnt compile(I tested it with a random Java class and my compiler threw an error just to be sure)
Instead i would do it as follows
Array2DNode<E>[][] newNodes = new Array2DNode<>()[rows][cols];
Then you should be fine, Besides you seem to start iterating from 1 in your second for
statement, Instead remove the first:
newNodes[countRows][0] = new Array2DNode<>();
And instead just start your cols iterator from 0, Which would be a bit cleaner!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.