2 Replies Latest reply: Mar 20, 2009 5:35 AM by JosAH RSS

    casting

    807588
      public class Assign {
          
          /** Creates a new instance of Assign */
          public Assign() {
          }
          
      int[] splats;
      int[] dats = new int[4];
      char[] letters = new char[5];
       splats= dats;   // getting compiler exception ---"identifier required" but its already defined in the code. Please clarify.
       splats = letters;  // Cant we assign int array object to char array object by using casting i.e. splats = (int)letters;
      
          
      }
        • 1. Re: casting
          800282
          bobz wrote:
          ... Cant we assign int array object to char array object by using casting i.e. splats = (int)letters;
          No, you'll have to cast each individual element in your array.
          • 2. Re: casting
            JosAH
            Besides the int[] and char[] issue, you can't drop statements just at the class/object level. You either need an initialization block for this or put your statements in a method.

            kind regards,

            Jos