Array casting : Array Type Casting « Type Casting « SCJP

Home
SCJP
1.Java Source And Data Type
2.Operators
3.Modifiers
4.Type Casting
5.Statements
6.Object Oriented
7.Thread
8.Utility Classes
9.File
SCJP » Type Casting » Array Type Casting 
4.4.5.Array casting
Both arrays must contain reference types (not primitives)
and it must be legal to cast an element of Oldtype to an element of Newtype.



public class MainClass {
  public static void main(String[] argv) {
    MyClass[] myClassArray = new MyClass[3];
    MySubclass[] mySubclassArray = new MySubclass[3];

    myClassArray = (MyClass[]) mySubclassArray;

    System.out.println();
  }
}

class MyClass {
}

class MySubclass extends MyClass {
}
4.4.Array Type Casting
4.4.1.An array may be converted to interface Cloneable
4.4.2.An array may be converted to the interface Serializable
4.4.3.An array may be converted to another array. (element type must be convertible)
4.4.4.Converting byte array to int array
4.4.5.Array casting
4.4.6.If the object is an array type, you can cast it to the Cloneable interface.
4.4.7.An object array can be cast to an parent class array type
4.4.8.You can cast a primitive array reference only to and from an Object or Cloneable reference.
4.4.9.Manipulate a reference to an array of Extend references
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.