Why do values of collected HashMap have to be cast while values of parent Map don't? RESOLVED
Post by:Al Johnston
, Ranch Hand
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.
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.
This thread has been viewed 3370 times.
All times above are in ranch (not your local) time.
The current ranch time is Oct 19, 2018 12:01:39.