i created a class derived of Object and I have a object array.
how to do cast object array to my class array?
public class CastArray{
public CastArray(){
}
public long toLong(){
return Long.parseLong(this.toString());
}
public double toDouble(){
return Double.parseDouble(this.toString());
}
public int toInteger(){
return Integer.parseInt(this.toString());
}
}<br />
return Error:
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [LBasic.CastArray;
The question is a bit vague but let me make an attempt to answer it. if the object array is actually an array of your class, you can do a direct cast to your array e.g.
A[] a = (A[]) objArray;. Alternatively, if you know that each element can be cast into your class (is an instance of your class or one of its sub classes), you can clone it by creating a new array and adding each element with a cast to your class. e.g.: