Attempting to implement code similar to that found in the higher-order-function example from http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-6
val button = new JButton("test")
button.addActionListener{ e:ActionEvent => println("test") }
add(button)
leads to the following
error: type mismatch;
found : (java.awt.event.ActionEvent) => Unit
required: java.awt.event.ActionListener
button.addActionListener{ e:ActionEvent => println("test") }
^
This is true at least with Scala compiler version 2.7.6.final on my system. I am able to achieve what I want in the Java-style way of explicitly implementing an anonymous ActionListener.
button.addActionListener( new ActionListener() {
def actionPerformed(e:ActionEvent) { println("test") }
})
As far as I understand, Scala should be able to use duck-typing to render this explicit implementation of ActionListener unnecessary; so why isn't it working here? I have next to no practical experience of duck-typing at this point.