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 2019/06/18 14:40:00 UTC
[jira] [Comment Edited] (GROOVY-9176) Syntactic sugar for set
method calls in conflict with class member declarations
[ https://issues.apache.org/jira/browse/GROOVY-9176?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16866660#comment-16866660 ]
Eric Milles edited comment on GROOVY-9176 at 6/18/19 2:39 PM:
--------------------------------------------------------------
Like this?
Pojo.java:
{code:java}
public class Pogo {
private String title;
public String getTitle() { return title; }
public void setTitle(String title) { this.title = title; }
}
{code}
Pogo.groovy:
{code:groovy}
import javax.swing.JLabel
class Pogo extends Pojo {
JLabel title = new JLabel('skin')
}
{code}
If this is what you are referring to, the "title" member is a property in Pogo. If you add "public", "private", "protected" or "@PackageScope" in front of it, it will be a field instead and you can refer to it or the parent classes "title" field/accessors as well.
was (Author: emilles):
Like this?
Pojo.java:
{code:java}
public class Pogo {
private String title;
public String getTitle() { return title; }
public void setTitle(String title) { this.title = title; }
}
{code}
Pogo.groovy:
{code:groovy}
import javax.swing.JLabel
class Pogo extends Pojo {
JLabel title = new JLabel('skin')
}
{code}
If this is what you are referring to, the "title" member is a property in Pogo. If you add "public", "private", "protected" or "@PackageScope" to it, it will be a field instead an you can refer to it or the parent classes "title" field/accessors as well.
> Syntactic sugar for set method calls in conflict with class member declarations
> -------------------------------------------------------------------------------
>
> Key: GROOVY-9176
> URL: https://issues.apache.org/jira/browse/GROOVY-9176
> Project: Groovy
> Issue Type: Bug
> Components: Compiler
> Affects Versions: 3.0.0-beta-1
> Reporter: David Ekholm
> Priority: Minor
>
> Groovy 3.0.0 beta 1 has broken code that earlier worked in Alpha 4:
> Say you have a Java class with a setTitle(String) method. Now you override this class with a Groovy class. In it you declare the following member variable:
> JLabel title = new JLabel("skin");
> This breaks the Groovy compiler in v3.0.0 beta 1 (but not alpha 4) with the following error:
> The return type of javax.swing.JLabel getTitle() in Script34$1$12 is incompatible with java.lang.String in se.datadosen.component.ControlPanel
> . At [-1:-1] @ line -1, column -1.
> Two things are noteworthy here:
> 1) The line number references (-1) are broken
> 2) Instead of letting the declared "title" variable hide the ability to call setTitle on the base class using the syntactic sugar of Groovy (foo = being syntactic sugar for setFoo(...)), it now bails out with this error, breaking Java compatibility. I expected this declaration to be allowed and simply hide the ability to call setTitle on the base class via that syntactic sugar.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)