Question

I notice that java doesn't accept the following command:

    ComboBox<String>[] comboGuesses = new ComboBox<String>[];

but it does accept:

    ArrayList<ComboBox<String>> comboGuesses = new ArrayList<ComboBox<String>>();

Since I am using generic array for every other type in javaFX, I wonder why this is not valid for Combo-Boxes.

Was it helpful?

Solution

Java can't create arrays of generic types or of objects that utilize generic types, such as ComboBox. Has something to do with the way arrays are allocated into memory at runtime - since the size of each contained object isn't well defined, Java can't make the array. You'll have to make do with an ArrayList or similar structure.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top