11 Replies Latest reply on Jul 18, 2009 1:06 PM by 843793

    Generic Class with two dimensional generic Argument

      Hi. I want to create a generic class Matrix. But I've got problems with the constructors. The compiler marks those parts as errors that have
       new T[rows][columns]
      in it. Can you help me with the correct Syntax?
      public class Matrix<T> {
           private T[][] m;
           private int rows;
           private int columns;
           protected Matrix (int rows, int columns){
                this.rows = rows;
                this.columns = columns;
                this.m = new T[rows][columns];
           public Matrix (T[][] m) throws MatrixException{
              if (m == null)
                  throw new MatrixException("Matrix must not be NULL.");
                this.rows = m.length;
                this.columns = m[0].length;
                this.m = new T[rows][columns];
                for (int r=0; r<rows; r++)
                     for (int s=0; s<columns; s++)
                          this.m[r][s] = m[r][s];