Am 23.01.2018 um 12:42 schrieb Jochen Theodorou:
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()
ahem... insert here, what I actually wanted to say...
These Test1.$staticClassInfo are references to static fields. You do not
need this.getClass() for this, as a subclass defines its own
$staticClassInfo. That means
this.getClass().getField("$staticClassInfo") will always and only choose
the current subclass. If that subclass is in Java, you will save the
metaclass for the Java subclass in the static field, that is supposed to
hold the metaclass for the base class. That's not good.
bye Jochen