This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Why do values of collected HashMap have to be cast while values of parent Map don't? RESOLVED  RSS feed

 
Ranch Hand
Posts: 99
Flex Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EDIT: DUH... I did not type Iterator properly... LOL. I had to cast because I did in fact goof up the code. This is resolved. Funny how I can take hours trying to figure something out and then as soon as I post here, I stumble upon the solution a few minutes later...


I'm writing an abstract object which needs to store values in a Map<String, Map<String, List<String>>>. When I loop the first parent Map, I get no complaints without casts (as expected). But, when I loop the inner Map, I get complaints that I have to cast from Object to List<String>? I'm happy to do so, but I'm curious if perhaps I'm doing something wrong.

Here's test code to demonstrate my question.



If I access a List<String> in the parent Map, I don't need to cast (for instance, I access the Map of the Map without a cast). But, I have to cast the Map<Map> values? Can someone help me understand why or tell me if I'm just goofing up my code?


******************* No Need To Read Further But More Context Below For Any Suffering Insomnia ******************

As always, I'm happy to hear of different ways to solve my problem. So, for any who may want to know more , here's what I'm trying to do...

I have an Object which manages the creation of content in a content management system. I want to give my clients the ability to define their content. One of the values that the user can define is "aspects" which are properties (aka Indicies in the EDMS world) which can be dynamically added to content at any time. Content that is added to the repo can have the following characteristics (when an Aspect is added):

1. A namespace
2. The Aspect Name
3. IF the aspect has Properties, a NamedValue[] of all the property names and values to set to the names.
4. Some other stuff.

In my super class, I can set a List<Object> of the above Aspect params. Since I don't know how many aspects a user may want to set, nor do I have any clue how many Properties any given aspect that is being set may have, I need a way to store and retrieve them to add them to build the List<Object> which this abstract object will pass to super. Super then accesses the values as follows:



The first code sample block describes how I build the List<Object> that the above code is iterating. The actual code is:



Any suggestions on more optimal ways to do this are appreciated.

Cheers,
Al
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!