From users-return-1426-apmail-groovy-users-archive=groovy.apache.org@groovy.apache.org Mon Feb 29 13:26:06 2016 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 A45C1194AE for ; Mon, 29 Feb 2016 13:26:06 +0000 (UTC) Received: (qmail 98210 invoked by uid 500); 29 Feb 2016 13:26:03 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 98177 invoked by uid 500); 29 Feb 2016 13:26:03 -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 98167 invoked by uid 99); 29 Feb 2016 13:26:03 -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; Mon, 29 Feb 2016 13:26:03 +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 D202A1A05AE for ; Mon, 29 Feb 2016 13:26:02 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.179 X-Spam-Level: X-Spam-Status: No, score=0.179 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_REPLY=1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx2-lw-us.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id mVO4uMLFVv_B for ; Mon, 29 Feb 2016 13:26:00 +0000 (UTC) Received: from mail-wm0-f47.google.com (mail-wm0-f47.google.com [74.125.82.47]) by mx2-lw-us.apache.org (ASF Mail Server at mx2-lw-us.apache.org) with ESMTPS id 587325F642 for ; Mon, 29 Feb 2016 13:26:00 +0000 (UTC) Received: by mail-wm0-f47.google.com with SMTP id l68so58350347wml.1 for ; Mon, 29 Feb 2016 05:26:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-transfer-encoding; bh=FUp1sRKts7aZNMMQdEhBGcgegYuGTKarV6p7yEX5YrQ=; b=ELghRU0YwWMAyH7ZWaAHaAvT+qCQmJQJxegzXkIYuTnwM1beAYarBr0S33WF5ifNtG JJJlEDzJ8jCk7l6ka+uYUMG2e7EVm3klRpoqZW44s1DqnMCJ9vJRCuANwF4KQ26NM3Gv ziOpvXSV7XgjABwujm3NTWyi7DQf/6q2+NXC67vV/2bu7lX1Zst8QtqgG2Wn3FX/lNCQ /FE4fNr2fODBPPlJYBoB8p+pWXnX8LLjK+JfFbNKPbTO3LVQ0cyqLQdmOa8eJGAnZzk4 vCtZkY69u/hoWtgpUJyx/KNUOXB/JELqSNrwjxDgxzmALHt7BQ86BWQrQJX4RXcwq77Z B1HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-transfer-encoding; bh=FUp1sRKts7aZNMMQdEhBGcgegYuGTKarV6p7yEX5YrQ=; b=IBZam9gIzVGrqk5uUqEVi0ryD1UiP1Crvem4vZMN1MskUyRdOzS//SBCHn2s5MAgIf kx8sHvQceHFFg60+0fGOhuxE5HAdAs2DtvgnEYQ33Xnw46rzXX1oaZ7VDVxF+SL9hmoc 5kmWugxBVLawOYY1larVIUWcLBrFogXsS2hYMgL4qUKJ9uK92st4kPIyL94pBRrQ3hkq CIkcagFh4nXUW5H03N+dN89vHSWxI/iS2jR1hZfyD1U9s/xVQy6fq6/kUeQkxhx9eSio 6JaF3hRrMu1ePPH0rv3lU7q2s+oM+eO1392PSNQ7Cp/Jx0Qe1G0ZOSQ8bOAoLSguoopd 1m2g== X-Gm-Message-State: AD7BkJL/zE75zw9f4Fe6RXaeZqswRauXRDasWKgJlTG8yLz6mLhLnPAMifsjRwVgLUHGgoz/V9OsUogxywx4mQ== X-Received: by 10.28.214.11 with SMTP id n11mr10801518wmg.31.1456752359218; Mon, 29 Feb 2016 05:25:59 -0800 (PST) MIME-Version: 1.0 Received: by 10.194.5.163 with HTTP; Mon, 29 Feb 2016 05:25:39 -0800 (PST) In-Reply-To: References: From: =?UTF-8?B?RGlua28gU3Jrb8SN?= Date: Mon, 29 Feb 2016 14:25:39 +0100 Message-ID: Subject: Re: Confirming getProperties() works differently (inside vs outside) To: users@groovy.apache.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 29 February 2016 at 13:48, Gerald Wiltse wrote: > This looks like an elegant solution. Are you confirming that there's no w= ay > for a method inside "class Chameleon" to achieve the goal? Just by movi= ng > method out to a trait, it becomes aware of all the inherited and implemen= ted > props? Not bad... I think I'd much rather C=C3=A9dric or Jochen confirm and explain this. I don't feel I could give you a fully accurate answer here - sorry. Cheers, Dinko > > THANKS! this list has been really awesome for learning. > > Gerald R. Wiltse > jerrywiltse@gmail.com > > > On Mon, Feb 29, 2016 at 4:30 AM, Dinko Srko=C4=8D = wrote: >> >> I know this is not exactly what you asked, but would something like >> this work for you? >> >> class Chameleon{ String color =3D "green" } >> >> trait ColorChanging { >> String lastColor >> def changeColor =3D {newcolor -> >> lastColor =3D this.color >> this.color =3D newcolor >> } >> } >> >> trait MyProps { >> void printAllMyProperties(){ >> this.properties.each{println it} >> } >> } >> >> def mylizard =3D new Chameleon().withTraits(ColorChanging, MyProps) >> >> mylizard.changeColor('blue') >> >> mylizard.printAllMyProperties() >> mylizard.properties.each{println it} >> >> Cheers, >> Dinko >> >> On 29 February 2016 at 03:23, Gerald Wiltse wrot= e: >> > Is there a way for the Chameleon class to ever see that it has a >> > "lastColor" >> > property? >> > >> > class Chameleon{ >> > String color =3D "green" >> > >> > void printAllMyProperties(){ >> > this.properties.each{println it} >> > } >> > >> > } >> > >> > trait ColorChanging { >> > String lastColor >> > def changeColor =3D {newcolor -> >> > lastColor =3D this.color >> > this.color =3D newcolor >> > } >> > } >> > >> > def mylizard =3D new Chameleon().withTraits(ColorChanging) >> > >> > mylizard.changeColor(blue) >> > >> > mylizard.printAllMyProperties() >> > mylizard.properties.each{println it} >> > >> > The outputs of the two above lines don't match. lastColor isn't >> > available >> > from inside the class. >> > >> > This seems like it should be possible, but I tried several things >> > including >> > the declaredFields property and could not get the desired effect. >> > >> > In this script, I'm looking for a way for my instance to reference all >> > the >> > properties it's received from the trait. I guess it's same situation >> > with >> > inheritance, and properties added by propertymissing. >> > >> > >> > >> > >> > Gerald R. Wiltse >> > jerrywiltse@gmail.com >> > > >