You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2021/09/26 19:34:00 UTC

[jira] [Assigned] (GROOVY-7003) Cannot assign closure to property of functional interface type

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

Eric Milles reassigned GROOVY-7003:
-----------------------------------

    Assignee: Eric Milles

> 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: Eric Milles
>            Priority: Major
>
> 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
(v8.3.4#803005)