groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel.Sun" <>
Subject About the native interface default method for Groovy 3
Date Tue, 12 Feb 2019 16:35:44 GMT
Hi all,

        I'm trying to find a solution to implement the native interface
default method for Groovy 3 and encounter the following problems. Any advice
is appreciated!

1) [Generating Fields] 
No matter whether STC is enabled or not, the following fields need to be
generated, but `private`, `transient ` are invalid modifier for field in
interface declaration. In addition, field `metaClass`  is not `static` so
`metaClass` can not be generated in interface either...

    private static org.codehaus.groovy.reflection.ClassInfo $staticClassInfo 
    public static transient boolean __$stMC 
    private transient groovy.lang.MetaClass metaClass 

2) [Generating Methods]
`protected` can not be used to define interface method.

protected synthetic $getStaticMetaClass()Lgroovy/lang/MetaClass;
public getMetaClass()Lgroovy/lang/MetaClass;
public setMetaClass(Lgroovy/lang/MetaClass;)V
public invokeMethod(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;
public getProperty(Ljava/lang/String;)Ljava/lang/Object;
public setProperty(Ljava/lang/String;Ljava/lang/Object;)V

// when STC is disabled, the following additional methods will be generated
private static synthetic $createCallSiteArray_1([Ljava/lang/String;)V
private static synthetic
private static synthetic

        As for all of the above `public` instance methods, we can transform
them to `default` instance methods.

        At last, I have a crazy idea, maybe we can generate all of the above
fields and methods with traits, but the default method is generated in a
native way, e.g.

// native interface
interface SomeInterfaceWithDefaultMethod {
        // native interface default method
        default void helloWorld() {
                 // generate bytecode here to use traits to invoke MOP


Apache Groovy committer 
Twitter: @daniel_sun 

Sent from:

View raw message