Pregunta

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.

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top