Modifying the elements in an private array from another class?

An example:

import java.lang.reflect.*;
 
public class Main
{
   public static void main(String []args) throws Exception {
      PrivateClass pc = new PrivateClass();
 
      pc.printArray();
 
      Class clazz = pc.getClass();
      Field field = clazz.getDeclaredField("privateArray");
      field.setAccessible(true);
      int []array = (int[]) field.get(pc);
 
      array[0] = 3;
      array[1] = 2;
      array[2] = 1;
 
      pc.printArray();
   }
}
 
class PrivateClass
{
   private int[] privateArray = { 1, 2, 3 };
 
   public void printArray() {
      System.out.print("[ ");
      for (int i=0; i<privateArray.length; i++) {
         System.out.print(privateArray[i] + " ");
      }
      System.out.println("]");
   }
}

outputs:

[ 1 2 3 ]
[ 3 2 1 ]