I have a function that gets as parameter an indefinite number of ImageButtons.
private void addButtons(ImageButton... ib) {
// ...
}
So this is perfect if I want to call it for example this way:
addButtons(button1, button2, button3);
But now it happens to me that I have to use as a parameter an unknown number of objects, for example an array. Inside addButtons the ImageButton parameters are used as an array, so I tried this:
ArrayList<ImageButton> ibs = new ArrayList<ImageButton>();
// feed the ibs ArrayList
addButtons((ImageButton[])ibs.toArray());
And I get a ClassCastException.
Why?