Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Arrays.deepToString causes problem with single dimensioned primitive array.

807580Nov 23 2009 — edited Nov 24 2009
Am I doing something wrong? I'm using Java 1.6.15 on windows and I try the following code which gives a class cast exception:
import java.util.Arrays;

public class NameTest {
   public static void main( String[] args ) {
      try {
         double[] tmp = new double[1];
         tmp[0] = 1.5;
         print( tmp );
      } catch ( Exception e ) {
         System.out.println( "Exception: " + e.getMessage() );
      }
      Double[] tmp1 = new Double[1];
      tmp1[0] = 1.5;
      print( tmp1 );
      double[][] tmp2 = new double[1][1];
      tmp2[0][0] = 1.5;
      print( tmp2 );

   }

   static void print( Object tmp ) {
      System.out.println( "Test =" + Arrays.deepToString( (Object[]) tmp ) );
   }

}
Output :

Exception: [D cannot be cast to [Ljava.lang.Object;
Test =[1.5]
Test =[[1.5]]
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 22 2009
Added on Nov 23 2009
14 comments
557 views