[英]class JComboBox takes type parameters
I want to get value of instance of JComboBox in my listener: 我想在侦听器中获取JComboBox实例的值:
object NoteListener extends ActionListener {
def actionPerformed(e:ActionEvent):Unit = {
println("Source: " + e.getSource.asInstanceOf[JComboBox].getValue)
}
}
And I get this error: 我得到这个错误:
[error] .../test.scala:30: class JComboBox takes type parameters
[error] println("Source: " + e.getSource.asInstanceOf[JComboBox].getValue)
when I try to pass any parameter: 当我尝试传递任何参数时:
[error] .../test.scala:30: ']' expected but '(' found.
[error] println("Source: " + e.getSource.asInstanceOf[JComboBox(Array)].getValue)
Is it a bug, or my ignorance? 是虫子还是我的无知?
Your type parameters are incorrect: 您的类型参数不正确:
e.getSource.asInstanceOf[JComboBox(Array)].getValue)
should be 应该
e.getSource.asInstanceOf[JComboBox[Array]].getValue)
Note the [Array]. 注意[Array]。 This is how you specify type parameters in Scala. 这是在Scala中指定类型参数的方式。
不确定,但这应为您提供JComboBox的实例
e.getSource.peer
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.