As I understand it, when they finally come along, we will be able to substitute a Java closure for the equivalent single-method interface. Is there a standard Scala idiom for doing the same – implementing a Java Single Abstract Method interface with a Scala closure?
Ideally I’d like the following to automagically work
test("Closure") {
var event: PropertyChangeEvent = null
var label = new JLabel()
label.addPropertyChangeListener( {e: PropertyChangeEvent => event = e} )
label.setText("fred")
event.getNewValue should be ("fred")
}
There was a lengthy discussion about this in January.
http://www.scala-lang.org/node/8744
The idea was well received, and even taken a bit further than this proposal. But the devil is in the details, and a prototype implementation may yet find other problems with this proposal.