groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nikolay Totomanov <ntotoma...@abv.bg>
Subject Strong typing in traits
Date Fri, 17 Jul 2015 17:11:33 GMT
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.
The problem is - the IDE do not know what kind of type it is and does not support refactoring/code
compition/etc - all the staff we are using the IDE for.
All suggestions would be highly appriciated
 
 trait  TraitA {

   def  fillInMap(){
    // here 'map' is with undefined type
    // is there a way to "suggest" its type 
    map.put( 'car1' , 'bmw1' ) 
    map.put( 'car2' , 'bmw2' )
  }
}
  
 class  ClassA  implements  TraitA{
  Map   map  =  new  HashMap ()

   public static void  main(String[] args) {
    ClassA classA =  new  ClassA()
    classA.fillInMap()

    classA. map .each { println it }

  }
} 
Mime
View raw message