• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

private instance variable of Map type

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how can I initialize in a constructor this private instance variable?

private Map<String, Set<Integer>> variable;

I tried to use :

variable = new HashMap<String, TreeSet<Integer>>();

because I want each set to be ordered but I get an error.
Any ideas guys?
Thank you.
 
author
Posts: 799
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You want to keep the bind types the same for the instantiated object:



but when you put elements into the map they can be of a concrete subtype:


If the client needs to know (doubtful in this case), or if you're worried about someone putting in a non-treeset instance, declare the map as binding to String and HashSet<Integer>.

Jeff
[ September 09, 2008: Message edited by: Jeff Langr ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic