title: In Java: using foreach loops in constructors to initialize multidimensional array data fields
body: <p>So I'm trying to make a class that encapsulates a 2D array of chars. In particular, what I want to do is define the default constructor so that the encapsulated 2D array contains the default char ('#' in this case). My problem: when I attempt to systematically fill the array with the default char via nested foreach loops, the compiler doesn't acknowledge that I am using the second nested loop's initialized char parameter c, although I obviously am with the assignment c = '#'. To quote Eclipse, "The value of the local variable c is not used."</p>
  
  <p>Here is the relevant code:</p>
  
  <pre><code>public class 2DCharArr
  {
   private char[][] chars;
   private byte length_x, length_y;
  
   public 2DCharArr()
   {
    length_x = 10; length_y = 10;
    chars = new char[length_x][length_y];
    for (char[] arr : chars)
     for (char c : arr)
      c = '#'; // Does not signal to Eclipse that c was used.
   }
  }
  </code></pre>
  
  <p>Is there something wrong with my syntax in the foreach loops, so that the compiler should fail to acknowledge my use of c? It would be great for someone to clear this up for me, since it is keeping me from using foreach loops to create objects that contain multi-dimensional arrays, though I feel like I should be able to if I'm ever to be very competent with the language. Thanks in advance for the insight!</p>