[ 
https://issues.apache.org/jira/browse/GROOVY-7003?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Pascal Schumacher updated GROOVY-7003:
--------------------------------------
    Affects Version/s:     (was: 2.4.0-rc-1)
                       2.4.5

> Cannot assign closure to property of functional interface type
> --------------------------------------------------------------
>
>                 Key: GROOVY-7003
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7003
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 2.3.6, 2.4.5
>            Reporter: Mauro Molinari
>            Assignee: Cédric Champeau
>
> I don't know if this is on purpose, but I can't understand why it should be.
> The following passes the static type checking right:
> {code}
> package test
> import java.beans.PropertyChangeEvent;
> import java.beans.PropertyChangeListener;
> import javax.swing.JFrame;
> import groovy.transform.CompileStatic;
> @CompileStatic
> class TestCompileStatic {
>       static final void main(String[] args) {
>               JFrame frame = new JFrame()
>               frame.name = 'foo'
>               PropertyChangeListener listener = { PropertyChangeEvent event ->
>                       println "Name changed: ${event.oldValue} -> 
> ${event.newValue}"
>               }
>               frame.addPropertyChangeListener('name', listener) 
>               frame.name = 'bar'
>       }
> }
> {code}
> The following does not:
> {code}
> package test
> import java.beans.PropertyChangeEvent;
> import java.beans.PropertyChangeListener;
> import javax.swing.JFrame;
> import groovy.transform.CompileStatic;
> @CompileStatic
> class TestCompileStatic2 {
>       static PropertyChangeListener listener = { PropertyChangeEvent event ->
>               println "Name changed: ${event.oldValue} -> ${event.newValue}"
>       }
>       
>       static final void main(String[] args) {
>               JFrame frame = new JFrame()
>               frame.name = 'foo'
>               
>               frame.addPropertyChangeListener('name', listener) 
>               frame.name = 'bar'
>       }
> }
> {code}
> The error is:
> {noformat}
> C:\ws\44\DCS-shop-trunk\TestGroovy\src\main\groovy\test\TestCompileStatic.groovy:
>  13: [Static type checking] - Cannot assign value of type groovy.lang.Closure 
> <
> java.lang.Void> to variable of type java.beans.PropertyChangeListener
>  @ line 13, column 43.
>    ertyChangeListener listener = { Property
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to