I have a weird compilation error. Offensive lines:
val comboBoxLanguage = new javax.swing.JComboBox //... comboBoxLanguage.setModel(new javax.swing.DefaultComboBoxModel( Array[Object]("Scala", "Java")))
and error:
error: type mismatch; found : Array[java.lang.Object] required: Array[Nothing with java.lang.Object] Note: java.lang.Object >: Nothing with java.lang.Object, but class Array is invariant in type T. You may wish to investigate a wildcard type such as `_ >: Nothing with java.lang.Object`. (SLS 3.2.10) comboBoxLanguage.setModel(new javax.swing.DefaultComboBoxModel( Array[Object]("Scala", "Java")))
According to JavaDoc, the DefaultComboBoxModel constructor expects Object[] , which can be String[] or any type of array in Java, since arrays are covariant, but they are not in Scala, so we should use Array[Object] , which should not be a problem .
Why does the compiler expect Array[Nothing with java.lang.Object] ? How can i fix this?
This is similar to version 2.9.1 from Scala. My application was used to compile until I installed 2.9.1 a couple of days ago. The confusing / disturbing thing is that I have not changed the version of the project compiler library in IntelliJ, but for some reason does it use it, perhaps grabbing it from my SCALA_HOME environment variable?
source share