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 2020/07/08 21:12:00 UTC

[jira] [Updated] (GROOVY-9278) Java compatibility: consider supporting local class definitions

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

Eric Milles updated GROOVY-9278:
--------------------------------
    Affects Version/s:     (was: 3.0.4)

> Java compatibility: consider supporting local class definitions
> ---------------------------------------------------------------
>
>                 Key: GROOVY-9278
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9278
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Eric Milles
>            Priority: Minor
>
> Consider the following Java code:
> {code:java}
> class Main {
>   public static void main(String[] args) {
>     class Local implements Runnable { // allows modifiers "final" and "abstract" only!
>       @Override public void run() {
>         System.out.println("works");
>       }
>     }
>     new Main().meth(new Local());
>   }
>   void meth(Runnable runnable) {
>     runnable.run();
>   }
> }
> {code}
> I was not aware this was supported until encountering it in another codebase.  Typically I would use an anonymous inner class in similar situations.  For increased cross-compatibility, Groovy could implement support for locally defined classes.  There is probably some Java spec that defines their characteristics.
> At the moment groovyc emits "Class definition not expected here. Please define the class at an appropriate place or perhaps try using a block/Closure instead." for this code.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)