From users-return-487-apmail-groovy-users-archive=groovy.apache.org@groovy.incubator.apache.org Sat Jul 18 07:50:18 2015 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 904FB185B3 for ; Sat, 18 Jul 2015 07:50:18 +0000 (UTC) Received: (qmail 74384 invoked by uid 500); 18 Jul 2015 07:50:13 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 74349 invoked by uid 500); 18 Jul 2015 07:50:13 -0000 Mailing-List: contact users-help@groovy.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.incubator.apache.org Delivered-To: mailing list users@groovy.incubator.apache.org Received: (qmail 74339 invoked by uid 99); 18 Jul 2015 07:50:13 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 18 Jul 2015 07:50:13 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id F419F186562 for ; Sat, 18 Jul 2015 07:50:12 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 4.891 X-Spam-Level: **** X-Spam-Status: No, score=4.891 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_REPLY=1, HTML_MESSAGE=3, KAM_LIVE=1, T_RP_MATCHES_RCVD=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); domainkeys=pass (1024-bit key) header.from=ntotomanov@abv.bg header.d=abv.bg; dkim=pass (1024-bit key) header.d=abv.bg Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id zz7W2SggFQfI for ; Sat, 18 Jul 2015 07:49:59 +0000 (UTC) Received: from smtp-out.abv.bg (smtp-out.abv.bg [194.153.145.70]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTP id 3ABA920F10 for ; Sat, 18 Jul 2015 07:49:59 +0000 (UTC) Received: from nm61.abv.bg (nm3.ni.bg [192.168.151.92]) by smtp-out.abv.bg (Postfix) with ESMTP id F07CD50DB5B for ; Sat, 18 Jul 2015 10:49:52 +0300 (EEST) DomainKey-Signature: a=rsa-sha1; s=smtp-out; d=abv.bg; c=simple; q=dns; b=Q8FZB7/flCoRRSbUS8u/XyfMQdbXCk7k8BBne+b7tOqKrq3YUr2PkQJlkVIUucqqH 0PdAW4l3o38vZtmnZqjRvZc5ntGzKwb2rkH+lKjuMLGy1cicZ2KlnvnPvvpwHUG9OO2 b+vupbrFyk1dzv5L/tzwM+OiHlszbqU3YqCopKU= DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=abv.bg; s=smtp-out; t=1437205792; bh=4+k3oLygxqAX5+HKPvrzO4qgEn5Nc0Frv83ouCFoEFI=; h=Date:From:To:Message-ID:In-Reply-To:References:Subject: MIME-Version:Content-Type:DKIM; b=HwhD3hIDoS1MT3gRfNy/vBOP0atDYiQl PXNLNaaa32pxfFids3B2eRNvgjEJxRlDpZbncUXtYgmtZirRPxRQg6otyWb0of+FrZ5 9ozgqn1DolqaccUHDOkOM9/hitn9gZXpvQwtM/LD5BxN+oXiqIjO9+64CBqfNUwbvEH pTgYs= Received: from nm3.abv.bg (localhost [127.0.0.1]) by nm61.abv.bg (Postfix) with ESMTP id E794D1FBE6 for ; Sat, 18 Jul 2015 10:49:52 +0300 (EEST) Date: Sat, 18 Jul 2015 10:49:52 +0300 (EEST) From: Nikolay Totomanov To: users@groovy.incubator.apache.org Message-ID: <1146098008.2128588.1437205792947.JavaMail.apache@nm3.abv.bg> In-Reply-To: <55A939FC.7050605@gmx.org> References: <2081307213.2112411.1437153093794.JavaMail.apache@nm3.abv.bg> <55A939FC.7050605@gmx.org> Subject: Re: Strong typing in traits MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_2128587_963477884.1437205792943" X-Mailer: AbvMail 3.0 X-Originating-IP: 188.126.6.222 ------=_Part_2128587_963477884.1437205792943 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Thanks blackdrag, I used local private variables in the trait to configure the types: trait TraitA { private Map map public void configTrait(Map map){ this . map =map } def fillInMap(){ map .put( 'car1' , 'bmw1' ) } } class ClassA implements TraitA{ Map map = new HashMap () public static void main(String[] args) { ClassA classA = new ClassA() classA.configTrait(classA. map ); classA.fillInMap() } } >-------- Оригинално писмо -------- >От: Jochen Theodorou blackdrag@gmx.org >Относно: Re: Strong typing in traits >До: users@groovy.incubator.apache.org >Изпратено на: 17.07.2015 20:23 Am 17.07.2015 19:11, schrieb Nikolay Totomanov: > Hello, > > I would like to have strong types in the traits which I use. > For example in the trait "TraitA" i have a method fillInMap() in which I > am adding elements to the "map" field [...] > traitTraitA { > > deffillInMap(){ > // here 'map' is with undefined type > // is there a way to "suggest" its type > map.put('car1','bmw1') > map.put('car2','bmw2') > } > } How about adding a method getMap or the like to the trait? bye blackdrag -- Jochen "blackdrag" Theodorou blog: http://blackdragsview.blogspot.com/ ------=_Part_2128587_963477884.1437205792943 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Thanks blackdrag, I used local private variables in the trait to configure = the types:
trait TraitA {

private Map = map

public void configTrait(Map map){
= this.map=3Dmap
}

def fillInMap(){
map.put('car1','bmw1')
}
}


class ClassA implements TraitA{
Map<String,String&= gt; map =3D new HashMap<String,String= >()

public stat= ic void main(String[] args) {
ClassA classA =3D new ClassA()
classA.conf= igTrait(classA.map);=
classA.fillInMap()
}
}




>-------- =D0=9E=D1=80=D0=B8=D0=B3=D0=B8=D0=BD=D0=B0=D0=BB=D0=BD=D0=BE = =D0=BF=D0=B8=D1=81=D0=BC=D0=BE --------
>=D0=9E=D1=82: Jochen Theodorou blackdrag@gmx.org
>=D0=9E=D1=82=D0=BD=D0=BE=D1=81=D0=BD=D0=BE: Re: Strong typing in t= raits
>=D0=94=D0=BE: users@groovy.incubator.apache.org
>=D0=98=D0=B7=D0=BF=D1=80=D0=B0=D1=82=D0=B5=D0=BD=D0=BE =D0=BD=D0= =B0: 17.07.2015 20:23

Am 17.07.2015 19:11, schrieb Nikolay Totomanov:
> Hello,
>
> I would like to have strong types in the traits which I use.
> For example in the trait "TraitA" i have a method fillInMap() in which= I
> am adding elements to the "map" field
[...]
> traitTraitA {
>
> deffillInMap(){
> // here 'map' is with undefined type
> // is there a way to "suggest" its type
> map.put('car1','bmw1')
> map.put('car2','bmw2')
> }
> }

How about adding a method getMap or the like to the trait?

bye blackdrag

--
Jochen "blackdrag" Theodorou
blog: htt= p://blackdragsview.blogspot.com/

------=_Part_2128587_963477884.1437205792943--