Am 23.01.2018 um 01:18 schrieb Daniel Sun:
Hi Jochen

$getStaticMetaClass can I think not be put in an interface. It needs
static information about the exact class this method is in and there is
supposed to be one for each Groovy class we create...

While I investigated the implementation of the instance method
`$getStaticMetaClass`, I found It seems that `$getStaticMetaClass` can also
be put in an interface too, because we can get static information via
reflection( e.g. `this.getClass().getField("$staticClassInfo")` )   ;-)
ah, instance method, so I did remember this part wrong, but the field $staticClassInfo is static. Frankly I question this logic quite a bit right now let me rewrite the bytecode a bit:

   protected synthetic $getStaticMetaClass()Lgroovy/lang/MetaClass;
     if (this.getClass()!=Test1.class) {
       return ScriptBytecodeAdapter.initMetaClass(this)
     } else {
       if (Test1.$staticClassInfo==null) {
         Test1.$staticClassInfo = ClassInfo.getClassInfo(this.getClass())
       }
    }
    return Test1.$staticClassInfo.getMetaClass()


I also intend to remove the meta
class in the class itself and have it 100% managed outside. But that
depends.
It will break many existing code. In addition, that will make Groovy less
object oriented IMHO, e.g. `groovyObj.foo()` VS
`InvokerHelper.invokeMethod(groovyObj, "foo", EMPTY_OBJECT_ARRAY)`, I prefer
the former...

Oh you compare wrong. groovyObj.foo() would still work. YOu ahve to compare

InvokerHelper.invokeMethod(groovyObj, "foo", EMPTY_OBJECT_ARRAY)

and

groovyObj.invokeMethod("foo", EMPTY_OBJECT_ARRAY)

I consider that a minor inconvenience on the user side, but a big win (in terms of cleaning up the MOP) on our side.

bye Jochen

Reply via email to