Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
2.4.0
-
None
Description
replacement description:
interface Intf { def foo = { "bar" } }
Will create an inner class that lacks the static modifier for the inner class table. Compare with
public interface JavaInterface { class NestedInInterface {} }
for reference
Original description:
The JLS specifies that an implicitly-declared constructor of a non-private inner class "implicitly declares one formal parameter representing the immediately enclosing instance of the class" (Section 8.8.9, see also 8.8.1).
interface Intf { def foo = { "bar" } }
The above code creates an inner class (Intf$1, not exactly sure what it's for) with a default constructor that has no parameters:
$ javap -p -classpath classes 'Intf$1' Compiled from "Intf.groovy" class Intf$1 implements groovy.lang.GroovyObject { ... public Intf$1(); ... }
While not a major issue, this non-conformance can break interoperability with anything that expects to work with Java classes. This particular example came up while trying to use a similarly-declared Groovy class from a Scala class, where the Scala compiler was unable to parse the generated inner class.
For reference, here is an example Java Inner class and it's compiled representation. Note the constructor parameter on the inner class.
public class JavaObj { public class Inner {} }
$ javap -p -classpath classes 'JavaObj$Inner' public class JavaObj$Inner { final JavaObj this$0; public JavaObj$Inner(JavaObj); }
Attachments
Issue Links
- is duplicated by
-
GROOVY-8032 nested classes on interfaces are not static
- Closed