A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
private instance variable of Map type
Joined: Sep 09, 2008
Sep 09, 2008 10:41:00
how can I initialize in a constructor this private instance variable?
, Set<Integer>> variable;
I tried to use :
variable = new
because I want each set to be ordered but I get an error.
Any ideas guys?
Joined: May 14, 2003
Sep 09, 2008 12:37:00
You want to keep the bind types the same for the instantiated object:
Map<String,Set<Integer>> v; v = new HashMap<String,Set<Integer>>();
but when you put elements into the map they can be of a concrete subtype:
v.put("a", new TreeSet<Integer>());
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
[ September 09, 2008: Message edited by: Jeff Langr ]
Modern C++ Programming with TDD
, Essential Java Style,
Agile in a Flash
I agree. Here's the link:
subject: private instance variable of Map type
how come generis type information at runtime/reflection ?
String as key to look up an Integer
Using toArray(Object) in java 5
What am I doing wrong?
How to copy a SQL result into a Map
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015