title: Java class does not recognize indexing
body: <p>I  made a Matrix class in JAVA that consists of a 2D int array with row and column variables. The constructor of the class generates a Matrix of dimensions n x m and I also implemented two methods that print the values of the Matrix and its transpose (<code>getMatrixValues</code> and <code>getTransposedValues</code>).</p>
  <p>However, I would like to make a function that takes as input a matrix and returns its transpose, but since this class is not an array I cannot iterate over it using <code>AT[j][i] = A[i][j]</code>, if I understand the exception correctly that IntelliJ is returning me (&quot;<em>java: array required, but Matrix found</em>&quot;).
  Obviously, I could simply use an int[][] class to begin with instead of defining a new class, but since I am new to JAVA and object-oriented programming in general I wondered whether there is not another possibility without discarding my Matrix class?</p>
  <p>Here is my code:</p>
  <pre><code>import java.util.Random;
  import java.util.Arrays;
  
  public class Matrix {
  
  
      private int n; // rows
      private int m; // cols
      private int[][] A; // matrix
  
      public static void main(String[] args){
          Matrix A = new Matrix(4,4);
  
          A.getMatrixValues();
  
          System.out.println(&quot;\n&quot;);
          
          A.getTransposedValues();
          
          Matrix AT = transposeMatrix(A);     
      }
  
      // constructor (randomly generates matrix)
      public Matrix(int rows, int cols){
  
          n = rows;
          m = cols;
  
          A = new int[rows][cols];
  
          Random r = new Random();
  //        r.setSeed(1);
  
          for(int i = 0; i &lt; rows; i++)
          {
              for(int j = 0; j &lt; cols ; j++)
              {
                  A[i][j] = r.nextInt(10);
              }
          }
      }
  
      // print matrix
      public void getMatrixValues(){
          for(int i=0;i&lt;n;i++)
          {
              for(int j=0;j&lt;m;j++)
              {
                  System.out.print(A[i][j]+&quot;\t&quot;);
              }
  
              System.out.print(&quot;\n&quot;);
          }
      }
  
      // print transposed matrix
      public void getTransposedValues(){
          for(int i=0;i&lt;n;i++)
          {
              for(int j=0;j&lt;m;j++)
              {
                  System.out.print(A[j][i]+&quot;\t&quot;);
              }
  
              System.out.print(&quot;\n&quot;);
          }
      }
  
  
      public static Matrix transposeMatrix(Matrix A){
  
          Matrix AT = new Matrix(A.get_n(), A.get_m());
  
          for(int i = 0; i &lt; A.get_n(); i++)
          {
              for(int j = 0; j &lt; A.get_m(); j++)
              {
                  AT[j][i] = A[i][j];
              }
          }
  
      return AT;
      }
  
      // getters
      public int get_n(){
          return n;
      }
  
      public int get_m(){
          return m;
      }
  
  
  }
  
  
  </code></pre>