I have this method getData as shown .
It is expecting an array of bag Objects as shown
please see the code below :
public static String getData(Bag[] bag)
{
}
public class Bag
{
public char side;
}
But , when i tried i am getting ClassCastException .
I have done this way :
Object bagArray[] = new Object[1];
Bag bagData = new Bag();
bagData.side = 'S';
bagArray[0]=bagData;
String bagData = ApplicationUtil.getData(Bag[]) bagArray);
Please let me , how to resolve this error ??
The problem is that
bagArrayis an array ofObjectand not an array ofBag.Either change that to
Bag bagArray[] = new Bag [1];or use aCollection(e.g.List) instead – note that you can castList<Object>toList<Bag>but that is an unsafe operation and not recommended unless you know what you’re doing.