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<String,String> map = new HashMap<String,String>()

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/