Return-Path: X-Original-To: apmail-groovy-users-archive@minotaur.apache.org Delivered-To: apmail-groovy-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 37E7419430 for ; Sun, 3 Apr 2016 15:34:12 +0000 (UTC) Received: (qmail 84482 invoked by uid 500); 3 Apr 2016 15:34:06 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 84454 invoked by uid 500); 3 Apr 2016 15:34:06 -0000 Mailing-List: contact users-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.apache.org Delivered-To: mailing list users@groovy.apache.org Received: (qmail 84444 invoked by uid 99); 3 Apr 2016 15:34:06 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 03 Apr 2016 15:34:06 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 5B1D51A040A for ; Sun, 3 Apr 2016 15:34:06 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.299 X-Spam-Level: X-Spam-Status: No, score=0.299 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001] autolearn=disabled Received: from mx2-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id V2WHYg9uLkZy for ; Sun, 3 Apr 2016 15:34:04 +0000 (UTC) Received: from smtp.czechia.com (smtp2.czechia.com [217.198.120.48]) by mx2-lw-eu.apache.org (ASF Mail Server at mx2-lw-eu.apache.org) with ESMTPS id C34BF5F1C6 for ; Sun, 3 Apr 2016 15:34:03 +0000 (UTC) Received: from [10.0.0.123] (31.4.broadband2.iol.cz [83.208.4.31]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: ocs@ocs.cz) by smtp.czechia.com (Postfix) with ESMTPSA id E2D618488E29 for ; Sun, 3 Apr 2016 17:33:56 +0200 (CEST) Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\)) Subject: Re: static propertyMissing in an interface From: OC In-Reply-To: <5700A8CD.50108@gmx.org> Date: Sun, 3 Apr 2016 17:33:54 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: References: <1459093137891-5732080.post@n5.nabble.com> <1459150970302-5732082.post@n5.nabble.com> <1459173202252-5732085.post@n5.nabble.com> <0CD793C2-B644-43CF-8E6B-22F19EB7F696@ocs.cz> <56FBECE0.1070308@gmx.org> <56FC1F8C.3090007@gmx.org> <64F3A2B8-4161-473B-B191-2A4A7FA7F54B@ocs.cz> <2F8979D6-A8E0-4633-A40E-59F548F21271@ocs.cz> <5700A8CD.50108@gmx.org> To: users@groovy.apache.org X-Mailer: Apple Mail (2.1510) Jochen, On 3. 4. 2016, at 7:23, Jochen Theodorou wrote: > On 01.04.2016 03:48, OC wrote: >> playing with possibilities of the i/i pattern, I have found one can = install a static property to an interface, and then use the property all = right -- see a proof-of-concept below. >>=20 >> Since it might be used e.g. to create instances or to get a factory = through public API based on interfaces (which would otherwise not be = possible without exposing the implementation class), this is truly = interesting. >>=20 >> The question is: can I rely on this rather arcane behaviour, that it = will not be broken in future Groovy versions? >=20 > if you want to be really sure it will continue working it is best if = you contribute a test case ;) But I see no plans to change that, = especially with java8 being able to define static methods and thus = static properties. Thanks a lot! > [...] >> def body=3D{-> "<$name in $delegate>" } >> delegate.metaClass.static."$getter"=3Dbody >> delegate."$getter"() // I wonder why just "body()" does not = work?!? >=20 > no idea why not... but you can always try body.call() instead. Same as with body(): =3D=3D=3D 6 /tmp> String getter=3D"get${name.capitalize()}" def body=3D{-> "<$name in $delegate>" } delegate.metaClass.static."$getter"=3Dbody body.call() // same problem with body(); delegate."$getter"() would = work though } println "- ${Root.weird}" } } interface Root {} 7 /tmp> groovy q.groovy Caught: groovy.lang.MissingMethodException: No signature of method: = java.io.StringWriter.capitalize() is applicable for argument types: () = values: [] groovy.lang.MissingMethodException: No signature of method: = java.io.StringWriter.capitalize() is applicable for argument types: () = values: [] at q$_main_closure1.doCall(q.groovy:5) at q.main(q.groovy:10) 8 /tmp>=20 =3D=3D=3D Thanks again and all the best, OC