You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2026/04/19 20:16:00 UTC
[jira] [Closed] (GROOVY-11803) Property shorthand not working for default methods in interfaces without @CompileStatic
[ https://issues.apache.org/jira/browse/GROOVY-11803?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King closed GROOVY-11803.
------------------------------
> Property shorthand not working for default methods in interfaces without @CompileStatic
> ---------------------------------------------------------------------------------------
>
> Key: GROOVY-11803
> URL: https://issues.apache.org/jira/browse/GROOVY-11803
> Project: Groovy
> Issue Type: Bug
> Reporter: Paul King
> Assignee: Eric Milles
> Priority: Major
> Fix For: 5.0.3
>
>
> The following script fails:
> {code:groovy}
> interface Foo {
> default int barSize() { bar.size() }
> String getBar()
> }
> class Baz implements Foo {
> String getBar() { 'BAR' }
> }
> assert new Baz().barSize() == 3
> {code}
> With this error:
> {noformat}
> groovy.lang.MissingPropertyException: No such property: bar for class: Baz
> {noformat}
> Workaround 1: Use getter:
> {code:groovy}
> interface Foo {
> default int barSize() { getBar().size() }
> String getBar()
> }
> class Baz implements Foo {
> String getBar() { 'BAR' }
> }
> assert new Baz().barSize() == 3
> {code}
> Workaround 2: use @CompileStatic:
> {code:groovy}
> @groovy.transform.CompileStatic
> interface Foo {
> default int barSize() { bar.size() }
> String getBar()
> }
> class Baz implements Foo {
> String getBar() { 'BAR' }
> }
> assert new Baz().barSize() == 3
> {code}
> I think this is a bug but if we can't get this to work for dynamic Groovy, I think we need to improve the documentation.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)