That works great! So far I've only used the static extensions, I did not know about this approach. Thank you :-)
Il giorno ven 17 lug 2020 alle ore 17:57 OCsite <o...@ocs.cz> ha scritto: > Alberto, > > far as I understand properly, at the very least you should be able to do > that programmatically, like this (do not forget > ExpandoMetaClass.enableGlobally()): > > def original=UnicastRemoteObject.metaClass.getMetaMethod("toString", > new Class[]) > UnicastRemoteObject.metaClass.toString={ -> > try { delegate.getName() } > catch (MissingMethodException e) { original.invoke(delegate) } > } > > There might possibly be an easier/more flexible solution, which I don't > see offhand. > > All the best, > OC > > On 17 Jul 2020, at 16:18, Alberto <alberto....@gmail.com> wrote: > > Hi all, > > I'm trying to extend a class so that it has a different toString, but only > in specific cases. > > I don't know for sure if this is possible, but what I'd like to do is: > > static String toString(UnicastRemoteObject self) { > try { > return self.getName(); > } catch (MissingMethodException e) { > return // return the to string from Unicast. > } > } > > Is it possible at all to call the original toString? > > Regards, > -- > Alberto Ingenito > > > -- Alberto Ingenito